The Splink Altair "blocking rules" chart is not displayed correctly when saved as PNG #3336
-
The Splink Altair blocking rules chart is displayed correctly in Vega Editor, see this shareable URL. The Vega Editor exports the chart correctly. The issue is that the chart saved to PNG using chart.save('chart.png') is not displayed correctly. I am an end-user. I originally raised the Splink issue 1990 against Splink but after learning that the chart is correct in the Vega Editor, I now think the issue instead is with Altair: Altair does not correctly save the Splink "blocking rules" Altair chart as PNG. Here is the correct Altair chart before saving: Here is the distorted chart after saving it as PNG. Note how much smaller the saved PNG chart is, possibly because of the unwanted added white space to the left of the y-title: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thank you for raising! I can reproduce the issue as such: import pandas as pd
import altair as alt
df = pd.DataFrame.from_records([
{
"row_count": 583013,
"rule": "(l.\"last_name\" = r.\"last_name\") AND (l.\"dob\" = r.\"dob\")",
"cumulative_rows": 583013,
"cartesian": 449211603714,
"reduction_ratio": "The rolling reduction ratio with your given blocking rule(s) is 0.999999. This represents the reduction in the total number of comparisons due to your rule(s).",
"start": 0
},
{
"row_count": 110803,
"rule": "(l.\"first_name\" = r.\"first_name\") AND (l.\"dob\" = r.\"dob\")",
"cumulative_rows": 693816,
"cartesian": 449211603714,
"reduction_ratio": "The rolling reduction ratio with your given blocking rule(s) is 0.999998. This represents the reduction in the total number of comparisons due to your rule(s).",
"start": 583013
},
{
"row_count": 63222,
"rule": "(l.\"zip\" = r.\"zip\") AND (l.\"sex\" = r.\"sex\") AND (l.\"last_name\" = r.\"last_name\") AND (l.\"first_name\" = r.\"first_name\")",
"cumulative_rows": 757038,
"cartesian": 449211603714,
"reduction_ratio": "The rolling reduction ratio with your given blocking rule(s) is 0.999998. This represents the reduction in the total number of comparisons due to your rule(s).",
"start": 693816
}
]
)
chart = alt.Chart(df).mark_bar().encode(
x='start',
x2='cumulative_rows',
y=alt.Y('rule').sort('-x'), # .axis(labelLimit=500)
color=alt.Color('rule').legend(None).scale(scheme='category20c')
)
chart import vl_convert as vlc
from IPython.display import Image
png_data = vlc.vegalite_to_png(vl_spec=chart.to_dict())
Image(png_data) As you can wee we are using vl_convert to export the specification into a png-file. Therefore raised the following issue within the vl_convert repository: vega/vl-convert#152 |
Beta Was this translation helpful? Give feedback.
Thank you for raising! I can reproduce the issue as such: