|
| 1 | +``sketch_seed`` parameter for rcParams |
| 2 | +-------------------------------------- |
| 3 | + |
| 4 | +`~matplotlib.rcParams` now has a new parameter ``path.sketch_seed``. |
| 5 | +Its default value is 0 and accepted values are any non negative integer. |
| 6 | +This allows the user to set the seed for the internal pseudo random number generator in one of three ways. |
| 7 | + |
| 8 | +1) Directly changing the rcParam: |
| 9 | + |
| 10 | + rcParams['path.sketch_seed'] = 20 |
| 11 | + |
| 12 | +2) Passing a value to the new *seed* parameter of `~matplotlib.pyplot.xkcd` function: |
| 13 | + |
| 14 | + plt.xkcd(seed=20) |
| 15 | + |
| 16 | +3) Passing a value to the new *seed* parameter of matplotlib.artist.set_sketch_params function: |
| 17 | + |
| 18 | + ln = plt.plot(x, y) |
| 19 | + ln[0].set_sketch_params(seed = 20) |
| 20 | + |
| 21 | +The seed will also have a changing characteristic for every artist which will be done in a deterministic manner. |
| 22 | + |
| 23 | + |
| 24 | +.. plot:: |
| 25 | + :include-source: true |
| 26 | + |
| 27 | + import matplotlib.pyplot as plt |
| 28 | + from matplotlib import rcParams |
| 29 | + |
| 30 | + with plt.xkcd(): |
| 31 | + rcParams['path.sketch_seed']=0 |
| 32 | + rcParams['path.sketch']=(2,120,40) |
| 33 | + pat,txt=plt.pie([10,20,30,40],wedgeprops={'edgecolor':'black'}) |
| 34 | + plt.legend(pat,['first','second','third','fourth'],loc='best') |
| 35 | + plt.title("seed = 0") |
| 36 | + plt.show() |
| 37 | + |
| 38 | +.. plot:: |
| 39 | + :include-source: true |
| 40 | + |
| 41 | + import matplotlib.pyplot as plt |
| 42 | + from matplotlib import rcParams |
| 43 | + |
| 44 | + fig, ax = plt.subplots() |
| 45 | + x = np.linspace(0.7, 1.42, 100) |
| 46 | + y = x ** 2 |
| 47 | + ln = ax.plot(x, y, color='black') |
| 48 | + ln[0].set_sketch_params(100, 100, 20, 40) |
| 49 | + plt.title("seed = 40") |
| 50 | + plt.show() |
| 51 | + |
| 52 | +.. plot:: |
| 53 | + :include-source: true |
| 54 | + |
| 55 | + import matplotlib.pyplot as plt |
| 56 | + from matplotlib import rcParams |
| 57 | + |
| 58 | + with plt.xkcd(seed=19680801): |
| 59 | + import matplotlib |
| 60 | + from matplotlib import gridspec |
| 61 | + |
| 62 | + rcParams['path.sketch']=(2,120,40) |
| 63 | + |
| 64 | + pat,txt=plt.pie([10,20,30,40],wedgeprops={'edgecolor':'black'}) |
| 65 | + plt.legend(pat,['first','second','third','fourth'],loc='best') |
| 66 | + plt.title("seed = 19680801") |
| 67 | + plt.show() |
0 commit comments