Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Description
Bug summary
Some theme properties are not properly forwarded toxkcd
plot.
Also, the displayed figure is not identical to the one saved.
Code for reproduction
importmatplotlib.pyplotaspltimportnumpyasnpfrommatplotlibimportpatheffectsplt.style.use(["dark_background"])defmake_figure():fig=plt.figure()ax=fig.add_axes((0.1,0.2,0.8,0.7))ax.spines[["top","right"]].set_visible(False)ax.set_xticks([])ax.set_yticks([])ax.set_ylim([-30,10])data=np.ones(100)data[70:]-=np.arange(30)ax.annotate("THE DAY I REALIZED\nI COULD COOK BACON\nWHENEVER I WANTED",xy=(70,1),arrowprops=dict(arrowstyle="->"),xytext=(15,-10), )ax.plot(data)ax.set_xlabel("time")ax.set_ylabel("my overall health")fig.text(0.5,0.05,'"Stove Ownership" from xkcd by Randall Munroe',ha="center")withplt.xkcd():# This figure will be in XKCD-stylemake_figure()# ...# This figure will be in regular stylemake_figure()plt.show()
Actual outcome
Shown figures
Saved figures
Expected outcome
By updating the relevantrcparams
after theplt.xkcd()
call, I can update the figure properly :
importmatplotlib.pyplotaspltimportnumpyasnpfrommatplotlibimportpatheffectsplt.style.use(["dark_background"])defmake_figure(type):fig=plt.figure()ax=fig.add_axes((0.1,0.2,0.8,0.7))ax.spines[["top","right"]].set_visible(False)ax.set_xticks([])ax.set_yticks([])ax.set_ylim([-30,10])data=np.ones(100)data[70:]-=np.arange(30)ax.annotate("THE DAY I REALIZED\nI COULD COOK BACON\nWHENEVER I WANTED",xy=(70,1),arrowprops=dict(arrowstyle="->"),xytext=(15,-10), )ax.plot(data)ax.set_xlabel("time")ax.set_ylabel("my overall health")fig.text(0.5,0.05,f"{type} type of figure",ha="center")withplt.xkcd():# This figure will be in XKCD-styleplt.rcParams["path.effects"]= [patheffects.withStroke(linewidth=0)]plt.rcParams["figure.facecolor"]="black"plt.rcParams["axes.edgecolor"]="white"make_figure("xkcd")# ...plt.savefig("xkcd_fig.png")# This figure will be in regular stylemake_figure("regular")plt.savefig("regular_fig.png")plt.show()
shown figures
saved figures
EDIT: moving theplt.style.use("dark_background")
result in a mix between thercparams
of the used style, and the ones imposed byxkcd
:
with plt.xkcd(): plt.style.use(["dark_background"]) # This figure will be in XKCD-style make_figure("xkcd_black") # ...plt.savefig("xkcd_fig.png")
Additional information
Based on thisissue on stackoverflow.
Operating system
Ubuntu 22.04
Matplotlib Version
3.8.2
Matplotlib Backend
QTAgg
Python version
3.10.12
Jupyter version
No response
Installation
pip
Metadata
Metadata
Assignees
Labels
No labels