Title: [Bug]: Theme properties are not properly forwarded to xkcd plot · Issue #27791 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Theme properties are not properly forwarded to xkcd plot · Issue #27791 · matplotlib/matplotlib
X Title: [Bug]: Theme properties are not properly forwarded to xkcd plot · Issue #27791 · matplotlib/matplotlib
Description: Bug summary Some theme properties are not properly forwarded to xkcd plot. Also, the displayed figure is not identical to the one saved. Code for reproduction import matplotlib.pyplot as plt import numpy as np from matplotlib import path...
Open Graph Description: Bug summary Some theme properties are not properly forwarded to xkcd plot. Also, the displayed figure is not identical to the one saved. Code for reproduction import matplotlib.pyplot as plt import...
X Description: Bug summary Some theme properties are not properly forwarded to xkcd plot. Also, the displayed figure is not identical to the one saved. Code for reproduction import matplotlib.pyplot as plt import...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/27791
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Theme properties are not properly forwarded to xkcd plot","articleBody":"### Bug summary\r\n\r\nSome theme properties are not properly forwarded to `xkcd` plot.\r\n\r\nAlso, the displayed figure is not identical to the one saved.\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\nfrom matplotlib import patheffects\r\n\r\nplt.style.use([\"dark_background\"])\r\n\r\n\r\ndef make_figure():\r\n fig = plt.figure()\r\n ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))\r\n ax.spines[[\"top\", \"right\"]].set_visible(False)\r\n ax.set_xticks([])\r\n ax.set_yticks([])\r\n ax.set_ylim([-30, 10])\r\n\r\n data = np.ones(100)\r\n data[70:] -= np.arange(30)\r\n\r\n ax.annotate(\r\n \"THE DAY I REALIZED\\nI COULD COOK BACON\\nWHENEVER I WANTED\",\r\n xy=(70, 1),\r\n arrowprops=dict(arrowstyle=\"-\u003e\"),\r\n xytext=(15, -10),\r\n )\r\n\r\n ax.plot(data)\r\n\r\n ax.set_xlabel(\"time\")\r\n ax.set_ylabel(\"my overall health\")\r\n fig.text(0.5, 0.05, '\"Stove Ownership\" from xkcd by Randall Munroe', ha=\"center\")\r\n\r\n\r\nwith plt.xkcd():\r\n # This figure will be in XKCD-style\r\n make_figure()\r\n # ...\r\n\r\n# This figure will be in regular style\r\nmake_figure()\r\n\r\nplt.show()\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\n# Shown figures\r\n\r\n\r\n\r\n# Saved figures\r\n\r\n\r\n\r\n\r\n### Expected outcome\r\n\r\nBy updating the relevant `rcparams` _**after**_ the `plt.xkcd()` call, I can update the figure properly :\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\nfrom matplotlib import patheffects\r\n\r\nplt.style.use([\"dark_background\"])\r\n\r\n\r\ndef make_figure(type):\r\n fig = plt.figure()\r\n ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))\r\n ax.spines[[\"top\", \"right\"]].set_visible(False)\r\n ax.set_xticks([])\r\n ax.set_yticks([])\r\n ax.set_ylim([-30, 10])\r\n\r\n data = np.ones(100)\r\n data[70:] -= np.arange(30)\r\n\r\n ax.annotate(\r\n \"THE DAY I REALIZED\\nI COULD COOK BACON\\nWHENEVER I WANTED\",\r\n xy=(70, 1),\r\n arrowprops=dict(arrowstyle=\"-\u003e\"),\r\n xytext=(15, -10),\r\n )\r\n\r\n ax.plot(data)\r\n\r\n ax.set_xlabel(\"time\")\r\n ax.set_ylabel(\"my overall health\")\r\n fig.text(0.5, 0.05, f\"{type} type of figure\", ha=\"center\")\r\n\r\n\r\nwith plt.xkcd():\r\n # This figure will be in XKCD-style\r\n plt.rcParams[\"path.effects\"] = [patheffects.withStroke(linewidth=0)]\r\n plt.rcParams[\"figure.facecolor\"] = \"black\"\r\n plt.rcParams[\"axes.edgecolor\"] = \"white\"\r\n make_figure(\"xkcd\")\r\n # ...\r\nplt.savefig(\"xkcd_fig.png\")\r\n\r\n# This figure will be in regular style\r\nmake_figure(\"regular\")\r\nplt.savefig(\"regular_fig.png\")\r\n\r\n\r\nplt.show()\r\n```\r\n\r\n# shown figures\r\n\r\n\r\n# saved figures\r\n\r\n\r\n\r\nEDIT: moving the `plt.style.use(\"dark_background\")` result in a mix between the `rcparams` of the used style, and the ones imposed by `xkcd`:\r\n\r\n```\r\nwith plt.xkcd():\r\n plt.style.use([\"dark_background\"])\r\n # This figure will be in XKCD-style\r\n make_figure(\"xkcd_black\")\r\n # ...\r\nplt.savefig(\"xkcd_fig.png\")\r\n```\r\n\r\n\r\n\r\n### Additional information\r\n\r\nBased on this [issue](https://stackoverflow.com/questions/50845646/matplotlib-xkcd-and-black-figure-background) on stackoverflow.\r\n\r\n### Operating system\r\n\r\nUbuntu 22.04\r\n\r\n### Matplotlib Version\r\n\r\n3.8.2\r\n\r\n### Matplotlib Backend\r\n\r\nQTAgg\r\n\r\n### Python version\r\n\r\n3.10.12\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\npip","author":{"url":"https://github.com/cgadal","@type":"Person","name":"cgadal"},"datePublished":"2024-02-14T14:08:25.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/27791/matplotlib/issues/27791"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f3beccf5-4174-216f-bcac-e51d893e867b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB0E:1A59AA:10AF0:154AD:6A52B35A |
| html-safe-nonce | f5461cf924e3e289902ba035747263629774c9f3b598b8a676dfa4d4b333d671 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjBFOjFBNTlBQToxMEFGMDoxNTRBRDo2QTUyQjM1QSIsInZpc2l0b3JfaWQiOiI3MTQ2MjUxNDg2OTM0MjUwMzMwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 6d97080ccfb0617df62e6770950bbea02996ac5667f4af292b06cad5ca532be8 |
| hovercard-subject-tag | issue:2134440084 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/27791/issue_layout |
| twitter:image | https://opengraph.githubassets.com/36f0e256407c30e386cec82dcd4acdcb9570a4726c8df2cef92efa246894935a/matplotlib/matplotlib/issues/27791 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/36f0e256407c30e386cec82dcd4acdcb9570a4726c8df2cef92efa246894935a/matplotlib/matplotlib/issues/27791 |
| og:image:alt | Bug summary Some theme properties are not properly forwarded to xkcd plot. Also, the displayed figure is not identical to the one saved. Code for reproduction import matplotlib.pyplot as plt import... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cgadal |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width