-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[ENH] xkcd.mplstyle w/ quasi parsing of patheffects.{functions} #26854
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
story645
wants to merge
3
commits into
matplotlib:main
Choose a base branch
from
story645:path-parse
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
path.effects rcParam can be set in stylesheet and new xkcd stylesheet | ||
--------------------------------------------------------------------- | ||
|
||
Can now set the ``path.effects`` :ref:`rcParam in a style sheet <customizing>` | ||
using a list of ``(patheffects function name, {**kwargs})``:: | ||
|
||
path.effects: ('Normal', ), ('Stroke', {'offset': (1, 2)}), ('withStroke', {'linewidth': 4, 'foreground': 'w'}) | ||
|
||
|
||
This feature means that the xkcd style can be used like any other stylesheet: | ||
|
||
.. plot:: | ||
:include-source: true | ||
:alt: plot where graph and text appear in a hand drawn comic like style | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
x = np.linspace(0, 2* np.pi, 100) | ||
y = np.sin(x) | ||
|
||
with plt.style.context('xkcd'): | ||
|
||
fig, ax = plt.subplots() | ||
ax.set_title("sine curve") | ||
ax.plot(x, y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,7 +163,6 @@ | |
from matplotlib._api import MatplotlibDeprecationWarning | ||
from matplotlib.rcsetup import validate_backend, cycler | ||
|
||
|
||
_log = logging.getLogger(__name__) | ||
|
||
__bibtex__ = r"""@Article{Hunter:2007, | ||
|
@@ -764,6 +763,14 @@ def __getitem__(self, key): | |
from matplotlib import pyplot as plt | ||
plt.switch_backend(rcsetup._auto_backend_sentinel) | ||
|
||
elif key == "path.effects" and self is globals().get("rcParams"): | ||
# defers loading of patheffects to avoid circular imports | ||
import matplotlib.patheffects as path_effects | ||
# use patheffects object or instantiate patheffects.object(**kwargs) | ||
return [pe if isinstance(pe, path_effects.AbstractPathEffect) | ||
else getattr(path_effects, pe[0])(**pe[1]) | ||
for pe in self._get('path.effects')] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to support third party patheffects too (e.g. |
||
|
||
return self._get(key) | ||
|
||
def _get_backend_or_none(self): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## default xkcd style | ||
|
||
# line | ||
lines.linewidth : 2.0 | ||
|
||
# font | ||
font.family : xkcd, xkcd Script, Comic Neue, Comic Sans MS | ||
font.size : 14.0 | ||
|
||
# axes | ||
axes.linewidth : 1.5 | ||
axes.grid : False | ||
axes.unicode_minus: False | ||
axes.edgecolor: black | ||
|
||
# ticks | ||
xtick.major.size : 8 | ||
xtick.major.width: 3 | ||
ytick.major.size : 8 | ||
ytick.major.width: 3 | ||
|
||
# grids | ||
grid.linewidth: 0.0 | ||
|
||
# figure | ||
figure.facecolor: white | ||
|
||
# path | ||
path.sketch : 1, 100, 2 | ||
path.effects: ('withStroke', {'linewidth': 4, 'foreground': 'w' }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.