Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legend cut off upon save() #3594

Open
ck578 opened this issue Sep 18, 2024 · 1 comment
Open

Legend cut off upon save() #3594

ck578 opened this issue Sep 18, 2024 · 1 comment
Labels

Comments

@ck578
Copy link

ck578 commented Sep 18, 2024

What happened?

I am generating a series of plots using altair and saving them as png files with .save(). All of the images render correctly in my editor, but upon saving the legend is cutting off on the right hand side. Here is my code and an example of the saved image

import altair as alt
import pandas as pd
from vega_datasets import data

data = {
    'Date': ['2024-01', '2024-01', '2024-01', '2024-02', '2024-02', '2024-02',
             '2024-03', '2024-03', '2024-03', '2024-04', '2024-04', '2024-04'],
    'Category': ['First category', 'Second Category', 'Third Category', 'First category', 'Second Category', 'Third Category', 'First category', 'Second Category', 'Third Category', 'First category', 'Second Category', 'Third Category'],
    'Value': [10, 15, 20, 25, 10, 15, 30, 20, 25, 35, 30, 20]
}

df = pd.DataFrame(data)

chart = alt.Chart(df).mark_bar().encode(
    x='Date:T',
    y='sum(Value):Q',
    color='Category:N',
    order='Category:N'
).properties(
    width=600,
    height=400,
    title='Stacked Bar Chart Trend Over Time'
).configure_axis(
    labelFontSize=12,
    titleFontSize=14
).configure_title(
    fontSize=16
)

chart.display()
chart.save(os.path.join(output_dir,'github_issue.png'))

github_issue

What would you like to happen instead?

I would like the saved file to match the rendered image. Here is what the image looks like before saving

image

Which version of Altair are you using?

5.2.0

@ck578 ck578 added the bug label Sep 18, 2024
@joelostblom
Copy link
Contributor

That chart looks correct when I run the code on Altair 5.4.1. Could you try updating? If that doesn't work, please list which version of vl-convert you have installed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants