dexplo / bar_chart_race

Create animated bar chart races in Python with matplotlib
MIT License
1.36k stars 352 forks source link

Outside axis labels are slightly blury and look different from labels within the axis. #42

Open slyuber opened 3 years ago

slyuber commented 3 years ago

Hey Guys!

First off, thank you so much for all the work you've put in to this great tool! Issue is basically described in the subject. The axis labels of all my plots are coming out a bit blurry.

Nothing crazy going on code wise, but here is the setup causing the issue:

bcr.bar_chart_race(df=plot_df, fixed_max= True, n_bars=8, period_length=1000, dpi = 300, period_fmt='Year: {x:.0f}', title = "Popularity of Bachelor Degrees in the US from 1970 to 2017", tick_label_size=9, perpendicular_bar_func='mean', cmap='set3', filter_column_colors=True, )

test21

mcaay commented 3 years ago

I'm having the same issue on Mac OS Catalina - @slyuber did you come up with a way to fix that?

chairuser commented 3 years ago

I was able to fix this by setting the figure background color. You have to create a figure yourself and pass that to the bar_chart_race function. This is the code:

# Set up a figure looking like bar_chart_race's default.
fig, ax = plt.subplots(figsize=(4, 2.5), dpi=144)
ax.set_facecolor('.8')
ax.tick_params(labelsize=8, length=0)
ax.grid(True, axis='x', color='white')
ax.set_axisbelow(True)
[spine.set_visible(False) for spine in ax.spines.values()]

# Setting background to a solid color fixes the problem.
fig.patch.set_facecolor('white')

# Do the thing.
bcr.bar_chart_race(df=plot_df, fig=fig)

My guess is that the font can't be properly antialiased on transparent background, which would explain why it looks fine inside the plot.