Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: Theme properties are not properly forwarded to xkcd plot #27791

Open
@cgadal

Description

@cgadal

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

image

Saved figures

xkcd_fig
regular_fig

Expected outcome

By updating the relevantrcparamsafter 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

image

saved figures

regular_fig
xkcd_fig

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")

xkcd_fig

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp