-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Add path.sketch_seed to control sketch randomness #31311
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
Aryan-Gore
wants to merge
11
commits into
matplotlib:main
Choose a base branch
from
Aryan-Gore:sketch-seed-work
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.
+293
−33
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fca1464
Added path.sketch_seed to rcParams
Aryan-Gore 4247c86
Add test for deterministic sketch seed behavior
Aryan-Gore 00c5d09
Fix Sketch constructor calls to pass seed argument in _backend_agg.h
Aryan-Gore 145ba70
Fix SketchParams type caster to handle 4-tuple including seed
Aryan-Gore 9e77069
Fix indentation in SketchParams type caster
Aryan-Gore cccf832
Fix ruff linting issues in test_path.py
Aryan-Gore 578d6be
Fix mypy and ruff linting issues
Aryan-Gore f5b9347
Add path.sketch_seed to _params_list in rcsetup.py
Aryan-Gore f0095ce
Move sketch_seed.rst to correct next_whats_new location
Aryan-Gore aa63bd6
added m_rand seed
Aryan-Gore b93dc07
Fix duplicate seed storage in sketch params
Aryan-Gore 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. | ||
|
|
||
|
|
||
| .. 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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move up next to
path.sketch.Is it a conscious decision to make this a separate parameter and not expand path.sketch to a 4-tuple? (Still accepting a 3-tuple for backward compatibility and in the validator adding seed=0). There may be usability aspects to warrant a separate parameter, OTOH it could also be reasonable to collect all sketch related parameters in a single structure; and it handled like this in the rest of the code.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was mostly to make implementation easier/cause internally it's managed separately from sketch:
#26050 (comment)
https://github.com/matplotlib/ProjectManagement/blob/f61f30f087c17098009bcb57adab0483b9d72a61/meeting_notes/2023/march_july.md?plain=1#L262