-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Sketch seed #26050
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
AryanSheka
wants to merge
1
commit into
matplotlib:main
Choose a base branch
from
AryanSheka:sketch-seed
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.
+259
−28
Open
Sketch seed #26050
Changes from all commits
Commits
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,13 @@ | ||
Seed for ``path.sketch`` will have a rolling (auto incrementing) behaviour | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The seed for the internal Pseudo number generator will now have an auto changing behavior. | ||
This means that the C code of every artist will get a different seed every time it is called | ||
and this will be done in a deterministic manner. | ||
|
||
Two figures sketched with the same parameters and different seed will look different from one another. | ||
|
||
``Artist.get_sketch_params()`` will now return a 4-tuple instead of a 3-tuple consisting of | ||
(scale, length, randomness, seed) of the form (float, float, float, int). | ||
|
||
See 'What's new' on how to set a value to the seed and its behaviour. |
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,67 @@ | ||
``sketch_seed`` parameter for rcParams | ||
-------------------------------------- | ||
|
||
`~matplotlib.rcParams` now has a new parameter ``path.sketch_seed``. | ||
Its default value is 0 and accepted values are any non negative integer. | ||
This allows the user to set the seed for the internal pseudo random number generator in one of three ways. | ||
|
||
1) Directly changing the rcParam: | ||
|
||
rcParams['path.sketch_seed'] = 20 | ||
|
||
2) Passing a value to the new *seed* parameter of `~matplotlib.pyplot.xkcd` function: | ||
|
||
plt.xkcd(seed=20) | ||
|
||
3) Passing a value to the new *seed* parameter of matplotlib.artist.set_sketch_params function: | ||
|
||
ln = plt.plot(x, y) | ||
ln[0].set_sketch_params(seed = 20) | ||
|
||
The seed will also have a changing characteristic for every artist which will be done in a deterministic manner. | ||
|
||
|
||
10000 .. plot:: | ||
:include-source: true | ||
|
||
import matplotlib.pyplot as plt | ||
from matplotlib import rcParams | ||
|
||
with plt.xkcd(): | ||
rcParams['path.sketch_seed']=0 | ||
rcParams['path.sketch']=(2,120,40) | ||
pat,txt=plt.pie([10,20,30,40],wedgeprops={'edgecolor':'black'}) | ||
plt.legend(pat,['first','second','third','fourth'],loc='best') | ||
plt.title("seed = 0") | ||
plt.show() | ||
|
||
.. plot:: | ||
:include-source: true | ||
|
||
import matplotlib.pyplot as plt | ||
from matplotlib import rcParams | ||
|
||
fig, ax = plt.subplots() | ||
x = np.linspace(0.7, 1.42, 100) | ||
y = x ** 2 | ||
ln = ax.plot(x, y, color='black') | ||
ln[0].set_sketch_params(100, 100, 20, 40) | ||
plt.title("seed = 40") | ||
plt.show() | ||
|
||
.. plot:: | ||
:include-source: true | ||
|
||
import matplotlib.pyplot as plt | ||
from matplotlib import rcParams | ||
|
||
with plt.xkcd(seed=19680801): | ||
import matplotlib | ||
from matplotlib import gridspec | ||
|
||
rcParams['path.sketch']=(2,120,40) | ||
|
||
pat,txt=plt.pie([10,20,30,40],wedgeprops={'edgecolor':'black'}) | ||
plt.legend(pat,['first','second','third','fourth'],loc='best') | ||
plt.title("seed = 19680801") | ||
plt.show() |
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
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 |
---|---|---|
|
@@ -823,7 +823,8 @@ def draw(self, renderer): | |
gc.set_foreground(ec_rgba, isRGBA=True) | ||
if self.get_sketch_params() is not None: | ||
scale, length, randomness = self.get_sketch_params() | ||
gc.set_sketch_params(scale/2, length/2, 2*randomness) | ||
seed = self._sketch_seed | ||
gc.set_sketch_params(scale/2, length/2, 2*randomness, seed) | ||
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. since this isn't incremented, are you sure that the rolling is correctly implemented? should have lines that look different - and yes please test if you haven't |
||
|
||
marker = self._marker | ||
|
||
|
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.2 KB
(110%)
lib/matplotlib/tests/baseline_images/test_path/xkcd_marker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.