positron
positron copied to clipboard
Python: Altair graphics do not properly align to vertical sizing of "container"
System details:
Positron Version: 2024.10.0 (Universal) build 13
Code - OSS Version: 1.93.0 Commit: 34b5c57cf211bcaf1bc48f75a8cd8d0b4378e5f5 Date: 2024-10-03T16:46:35.447Z Electron: 30.4.0 Chromium: 124.0.6367.243 Node.js: 20.15.1 V8: 12.4.254.20-electron.0 OS: Darwin arm64 24.0.0
Interpreter details:
Python 3.12.0 in Script
Describe the issue:
By default, Altair graphics do not resize even though they are interactive. This is "working as intended".
Using the .properties() function with set dimensions seems to work fine to hard-code the size in the Plot pane.
Using the .properties(width='container') will properly resize the plot according to the width of the Plot pane.
Using the .properties(height='container') or combinations with width will NOT resize the plot according to the width of the Plot pane. It seems to smash the plot to the top of the Plot pane. Also, if you resize vertically, then the graph will continue to "grow" beyond what is appropriate for the Plot pane. Moving focus to a different pane will then "reset" the graphic back to smashed against top.
https://github.com/user-attachments/assets/f06100f7-fc12-41b2-b27d-05ae402cfa24
Alternatively, here's a full example of several variations:
https://github.com/user-attachments/assets/c8eb2f3b-16c4-465a-b59a-5cd88281422c
Steps to reproduce the issue:
Use the Py Script below and resize the Plot pane in both vertical or horizontal directions.
#! pip install altair vega_datasets
import altair as alt
from vega_datasets import data
source = data.cars()
base_plt = alt.Chart(source).mark_circle(size=60).encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Origin',
tooltip=['Name', 'Origin', 'Horsepower', 'Miles_per_Gallon']
).interactive()
base_plt.properties(
width=800,
height=300
)
base_plt.properties(
width="container"
)
base_plt.properties(
width="container",
height=600
)
base_plt.properties(
height="container"
)
base_plt.properties(
width="container",
height="container"
)
Expected or desired behavior:
Ideally, the height="container" would act like our other supported graphics and fit to the size of the plot.