altair icon indicating copy to clipboard operation
altair copied to clipboard

chart.save() method producing SVGs with corrupted characters if e.g., umlaute ü, ö, ä, are present - but export via widget works correctly

Open christophgoebel opened this issue 5 years ago • 4 comments
trafficstars

Hi,

I'd like to use altairs export function to save svg files locally. I use German labels containing umlaute (üäö) and some other special characters. The method corrupts those characters, so I believe it could be a unicode issue. Exporting via the widget (the dropdown displayed in "notebook" mode) works fine.

Would be great to fix this!

Thanks!

Try this little script to reproduce the error:

import altair as alt
import pandas as pd

source = pd.DataFrame({'Activity': ['Sleeping', 'Eäting', 'TV', 'Wörk', 'Exercise'],
                           'Time': [8, 2, 4, 8, 2]})

chart = alt.Chart(source).transform_joinaggregate(
    TotalTime='sum(Time)',
).transform_calculate(
    PercentOfTotal="datum.Time / datum.TotalTime"
).mark_bar().encode(
    alt.X('PercentOfTotal:Q', axis=alt.Axis(format='.0%')),
    y='Activity:N'
)

display(chart)
chart.save("test.svg")

christophgoebel avatar Dec 12 '19 19:12 christophgoebel

Thanks for the report.

I ran the above script with Python 3.6, altair 4.0, selenium 3.14.1, and chromedriver 2.36.540469, and the saved output did not include any corrupted characters.

What package versions are you using?

jakevdp avatar Dec 13 '19 14:12 jakevdp

I'm using Python 3.7.3, altair 4.0, selenium 3.141.0, and chromedriver 79.0.3945.36 (according to cromedriver --version), which matches my chrome version (79.0.3945.79).

Problem persists.

I'll test a python downgrade... but it should not depend on this, right?

christophgoebel avatar Dec 14 '19 11:12 christophgoebel

Ok, tried using Python3.6 as well. The error is still there...

Again, if I use the "Save as SVG" button, the export works fine.

christophgoebel avatar Dec 15 '19 17:12 christophgoebel

I tried this and it works for me, as does the example in https://github.com/altair-viz/altair/issues/2200. @christophgoebel could you confirm whether you are still experiencing this issue with Altair 4.2.0. If so, could you share with OS you are on?

joelostblom avatar Mar 23 '22 00:03 joelostblom

Closing as issue is stale and cannot be reproduced.

binste avatar May 26 '23 16:05 binste