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

Fix xkcd() not resetting context anymore.#9603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Kojoley merged 1 commit intomatplotlib:masterfromanntzer:xkcd
Oct 28, 2017
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 33 additions & 23 deletionslib/matplotlib/pyplot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,9 +21,9 @@
import six

import sys
import warnings
import time
import types
import warnings

from cycler import cycler
import matplotlib
Expand DownExpand Up@@ -389,28 +389,38 @@ def xkcd(scale=1, length=100, randomness=2):
"xkcd mode is not compatible with text.usetex = True")

from matplotlib import patheffects
context = rc_context()
try:
rcParams['font.family'] = ['xkcd', 'Humor Sans', 'Comic Sans MS']
rcParams['font.size'] = 14.0
rcParams['path.sketch'] = (scale, length, randomness)
rcParams['path.effects'] = [
patheffects.withStroke(linewidth=4, foreground="w")]
rcParams['axes.linewidth'] = 1.5
rcParams['lines.linewidth'] = 2.0
rcParams['figure.facecolor'] = 'white'
rcParams['grid.linewidth'] = 0.0
rcParams['axes.grid'] = False
rcParams['axes.unicode_minus'] = False
rcParams['axes.edgecolor'] = 'black'
rcParams['xtick.major.size'] = 8
rcParams['xtick.major.width'] = 3
rcParams['ytick.major.size'] = 8
rcParams['ytick.major.width'] = 3
except:
context.__exit__(*sys.exc_info())
raise
return context
xkcd_ctx = rc_context({
'font.family': ['xkcd', 'Humor Sans', 'Comic Sans MS'],
'font.size': 14.0,
'path.sketch': (scale, length, randomness),
'path.effects': [patheffects.withStroke(linewidth=4, foreground="w")],
'axes.linewidth': 1.5,
'lines.linewidth': 2.0,
'figure.facecolor': 'white',
'grid.linewidth': 0.0,
'axes.grid': False,
'axes.unicode_minus': False,
'axes.edgecolor': 'black',
'xtick.major.size': 8,
'xtick.major.width': 3,
'ytick.major.size': 8,
'ytick.major.width': 3,
})
xkcd_ctx.__enter__()

# In order to make the call to `xkcd` that does not use a context manager
# (cm) work, we need to enter into the cm ourselves, and return a dummy
# cm that does nothing on entry and cleans up the xkcd context on exit.
# Additionally, we need to keep a reference to the dummy cm because it
# would otherwise be exited when GC'd.

class dummy_ctx(object):
def __enter__(self):
pass

__exit__ = xkcd_ctx.__exit__

return dummy_ctx()


## Figures ##
Expand Down
15 changes: 14 additions & 1 deletionlib/matplotlib/tests/test_style.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@
import pytest

import matplotlib as mpl
from matplotlib import style
from matplotlib importpyplot as plt,style
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Just out of curiosity, is this import style "ok"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah, doingimport sys, os is what is discouraged.

In that case that you are importing mulitple top level things is obscured, in this case we are importing multiple things from the same namespace (and renaming one).https://www.python.org/dev/peps/pep-0008/#imports

from matplotlib.style.core import USER_LIBRARY_PATHS, STYLE_EXTENSION

import six
Expand DownExpand Up@@ -158,3 +158,16 @@ def test_alias(equiv_styles):
rc_base = rc_dicts[0]
for nm, rc in zip(equiv_styles[1:], rc_dicts[1:]):
assert rc_base == rc


def test_xkcd_no_cm():
assert mpl.rcParams["path.sketch"] is None
plt.xkcd()
assert mpl.rcParams["path.sketch"] == (1, 100, 2)


def test_xkcd_cm():
assert mpl.rcParams["path.sketch"] is None
with plt.xkcd():
assert mpl.rcParams["path.sketch"] == (1, 100, 2)
assert mpl.rcParams["path.sketch"] is None

[8]ページ先頭

©2009-2025 Movatter.jp