Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 673f6c5

Browse files
committed
Merge pull request #5774 from mdboom/style-change2
API: Style changes omnibus PR
2 parents 069785d + b394ae7 commit 673f6c5

File tree

77 files changed

+3313
-3179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3313
-3179
lines changed

doc/users/whats_new/rcparams.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Configuration (rcParams)
2222
``svg.hashsalt``
2323
````````````````
2424

25-
If ``svg.hashsalt`` is ``None`` (which it is by default), the svg backend uses ``uuid4`` to generate the hash salt.
26-
If it is not ``None``, it must be a string that is used as the hash salt instead of ``uuid4``.
27-
This allows for deterministic SVG output.
25+
If ``svg.hashsalt`` is ``None`` (which it is by default), the svg
26+
backend uses ``uuid4`` to generate the hash salt. If it is not
27+
``None``, it must be a string that is used as the hash salt instead of
28+
``uuid4``. This allows for deterministic SVG output.

doc/users/whats_new/style_changes.rst

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Changes to the default style
2+
----------------------------
3+
4+
The most important changes in matplotlib 2.0 are the changes to the
5+
default style.
6+
7+
While it is impossible to select the best default for all cases, these
8+
are designed to work well in the most common cases.
9+
10+
These changes include:
11+
12+
Colors
13+
``````
14+
15+
- The default figure background color has changed from grey to white.
16+
Use the rcParam ``figure.facecolor`` to control this.
17+
18+
- The default cycle of colors to draw lines, markers and other content
19+
has been changed. It is based on the `Vega category10 palette
20+
<https://github.com/vega/vega/wiki/Scales#scale-range-literals>`__.
21+
22+
- The default color map used for images and pcolor meshes, etc., has
23+
changed from ``jet`` to ``viridis``.
24+
25+
- For markers, scatter plots, bar charts and pie charts, there is no
26+
longer a black outline around filled markers by default.
27+
28+
- Grid lines are light grey solid 1pt lines. They are no longer dashed by
29+
default.
30+
31+
Plot layout
32+
```````````
33+
34+
- The default dpi used for on-screen is now 100, which is the same as
35+
the old default for saving files. Due to this, the on-screen
36+
display is now more what-you-see-is-what-you-get.
37+
38+
- The number of ticks on an axis is now automatically determined based
39+
on the length of the axis.
40+
41+
- The limits are scaled to exactly the dimensions of the data, plus 5%
42+
padding. The old behavior was to scale to the nearest "round"
43+
numbers. To use the old behavior, set the ``rcParam``
44+
``axes.autolimit_mode`` to ``round_numbers``. To control the
45+
margins on particular side individually, pass any of the following
46+
to any artist or plotting function:
47+
48+
- ``top_margin=False``
49+
- ``bottom_margin=False``
50+
- ``left_margin=False``
51+
- ``right_margin=False``
52+
53+
- Ticks now point outward by default. To have ticks pointing inward,
54+
use the ``rcParams`` ``xtick.direction`` and ``ytick.direction``.
55+
56+
- By default, caps on the ends of errorbars are not present. Use the
57+
rcParam ``errorbar.capsize`` to control this.
58+
59+
Images
60+
``````
61+
62+
- The default mode for image interpolation, in the rcParam
63+
``image.interpolation``, is now ``nearest``.
64+
65+
- The default shading mode for light source shading, in
66+
``matplotlib.colors.LightSource.shade``, is now ``overlay``.
67+
Formerly, it was ``hsv``.
68+
69+
- The default value for the rcParam ``image.resample`` is now
70+
``True``. This will apply interpolation for both upsampling and
71+
downsampling of an image.
72+
73+
Fonts
74+
`````
75+
76+
- The default font has changed from "Bitstream Vera Sans" to "DejaVu
77+
Sans". "DejaVu Sans" is an improvement on "Bistream Vera Sans" that
78+
adds more international and math characters, but otherwise has the
79+
same appearance.
80+
81+
- The default math font when using the built-in math rendering engine
82+
(mathtext) has changed from "Computer Modern" (i.e. LaTeX-like) to
83+
"DejaVu Sans". To revert to the old behavior, set the ``rcParam``
84+
``mathtext.fontset`` to ``cm``. This change has no effect if the
85+
TeX backend is used (i.e. ``text.usetex`` is ``True``).
86+
87+
Dates
88+
`````
89+
90+
- The default date formats are now all based on ISO format, i.e., with
91+
the slowest-moving value first. The date formatters are still
92+
changeable through the ``date.autoformatter.*`` rcParams. Python's
93+
``%x`` and ``%X`` date formats may be of particular interest to
94+
format dates based on the current locale.
95+
96+
Legends
97+
```````
98+
99+
- By default, the number of points displayed in a legend is now 1.
100+
101+
- The default legend location is ``best``, so the legend will be
102+
automatically placed in a location to obscure the least amount of
103+
data possible.
104+
105+
- The legend now has rounded corners by default.

examples/api/demo_affine_image.py

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def imshow_affine(ax, z, *kl, **kwargs):
3737

3838
fig, (ax1, ax2) = plt.subplots(1, 2)
3939
Z = get_image()
40-
im1 = imshow_affine(ax1, Z, interpolation='none', cmap=cm.jet,
40+
im1 = imshow_affine(ax1, Z, interpolation='none',
4141
origin='lower',
4242
extent=[-2, 4, -3, 2], clip_on=True)
4343

@@ -48,15 +48,15 @@ def imshow_affine(ax, z, *kl, **kwargs):
4848
x1, x2, y1, y2 = im1.get_extent()
4949
x3, y3 = x2, y1
5050

51-
ax1.plot([x1, x2, x2, x1, x1], [y1, y1, y2, y2, y1], "r--", lw=3,
51+
ax1.plot([x1, x2, x2, x1, x1], [y1, y1, y2, y2, y1], "--",
5252
transform=trans_data2)
5353

5454
ax1.set_xlim(-3, 5)
5555
ax1.set_ylim(-4, 4)
5656

5757
# image skew
5858

59-
im2 = ax2.imshow(Z, interpolation='none', cmap=cm.jet,
59+
im2 = ax2.imshow(Z, interpolation='none',
6060
origin='lower',
6161
extent=[-2, 4, -3, 2], clip_on=True)
6262
im2._image_skew_coordinate = (3, -2)

examples/api/filled_step.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ def filled_hist(ax, edges, values, bottoms=None, orientation='v',
6161
values = np.r_[values, values[-1]]
6262
bottoms = np.r_[bottoms, bottoms[-1]]
6363
if orientation == 'h':
64-
return ax.fill_betweenx(edges, values, bottoms, **kwargs)
64+
return ax.fill_betweenx(edges, values, bottoms, left_margin=False,
65+
**kwargs)
6566
elif orientation == 'v':
66-
return ax.fill_between(edges, values, bottoms, **kwargs)
67+
return ax.fill_between(edges, values, bottoms, bottom_margin=False,
68+
**kwargs)
6769
else:
6870
raise AssertionError("you should never be here")
6971

@@ -206,3 +208,5 @@ def stack_hist(ax, stacked_data, sty_cycle, bottoms=None,
206208
ax1.set_xlabel('counts')
207209
ax1.set_ylabel('x')
208210
ax2.set_ylabel('x')
211+
212+
plt.show()

examples/api/histogram_path_demo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
barpath = path.Path.make_compound_path_from_polys(XY)
3737

3838
# make a patch out of it
39-
patch = patches.PathPatch(
40-
barpath, facecolor='blue', edgecolor='gray', alpha=0.8)
39+
patch = patches.PathPatch(barpath, facecolor='blue')
4140
ax.add_patch(patch)
4241

4342
# update the view limits

examples/api/image_zcoord.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
X = 10*np.random.rand(5, 3)
1010

1111
fig, ax = plt.subplots()
12-
ax.imshow(X, cmap=cm.jet, interpolation='nearest')
12+
ax.imshow(X, interpolation='nearest')
1313

1414
numrows, numcols = X.shape
1515

examples/api/patch_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
patches.append(polygon)
4040

4141
colors = 100*np.random.rand(len(patches))
42-
p = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.4)
42+
p = PatchCollection(patches, alpha=0.4)
4343
p.set_array(np.array(colors))
4444
ax.add_collection(p)
4545
plt.colorbar(p)

examples/api/power_norm_demo.py

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
for i, gamma in enumerate(gammas):
2121
plt.subplot(xgrid, ygrid, i + 2)
22-
plt.title('Power law normalization\n$(\gamma=%1.1f)$' % gamma)
22+
plt.title('Power law\n$(\gamma=%1.1f)$' % gamma)
2323
plt.hist2d(data[:, 0], data[:, 1],
2424
bins=100, norm=mcolors.PowerNorm(gamma))
2525

26-
plt.subplots_adjust(hspace=0.39)
26+
plt.tight_layout()
27+
2728
plt.show()

examples/api/sankey_demo_basics.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@
4242
orientations=[-1, 1, 0, 1, 1, 1, -1, -1, 0],
4343
pathlengths=[0.25, 0.25, 0.25, 0.25, 0.25, 0.6, 0.25, 0.25,
4444
0.25],
45-
patchlabel="Widget\nA",
46-
alpha=0.2, lw=2.0) # Arguments to matplotlib.patches.PathPatch()
45+
patchlabel="Widget\nA") # Arguments to matplotlib.patches.PathPatch()
4746
diagrams = sankey.finish()
48-
diagrams[0].patch.set_facecolor('#37c959')
4947
diagrams[0].texts[-1].set_color('r')
5048
diagrams[0].text.set_fontweight('bold')
5149
# Notice:
@@ -66,7 +64,7 @@
6664
sankey = Sankey(ax=ax, unit=None)
6765
sankey.add(flows=flows, label='one',
6866
orientations=[-1, 1, 0, 1, 1, 1, -1, -1, 0])
69-
sankey.add(flows=[-0.25, 0.15, 0.1], fc='#37c959', label='two',
67+
sankey.add(flows=[-0.25, 0.15, 0.1], label='two',
7068
orientations=[-1, -1, -1], prior=0, connect=(0, 0))
7169
diagrams = sankey.finish()
7270
diagrams[-1].patch.set_hatch('/')

examples/api/sankey_demo_links.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
def side(sankey, n=1):
1313
"""Generate a side chain."""
1414
prior = len(sankey.diagrams)
15-
colors = cycle(['orange', 'b', 'g', 'r', 'c', 'm', 'y'])
1615
for i in range(0, 2*n, 2):
1716
sankey.add(flows=[1, -1], orientations=[-1, -1],
18-
patchlabel=str(prior + i), facecolor=next(colors),
17+
patchlabel=str(prior + i),
1918
prior=prior + i - 1, connect=(1, 0), alpha=0.5)
2019
sankey.add(flows=[1, -1], orientations=[1, 1],
21-
patchlabel=str(prior + i + 1), facecolor=next(colors),
20+
patchlabel=str(prior + i + 1),
2221
prior=prior + i, connect=(1, 0), alpha=0.5)
2322

2423

examples/api/sankey_demo_old.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def put_labels(labels, positions, output=True):
187187

188188
patch, (intexts, outtexts) = sankey(ax, outputs=outputs,
189189
outlabels=outlabels, inputs=inputs,
190-
inlabels=None, fc='g', alpha=0.2)
190+
inlabels=None)
191191
outtexts[1].set_color('r')
192192
outtexts[-1].set_fontweight('bold')
193193

examples/api/skewt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ def _set_lim_and_transforms(self):
238238

239239
# Plot the data using normal plotting functions, in this case using
240240
# log scaling in Y, as dicatated by the typical meteorological plot
241-
ax.semilogy(T, p, 'r')
242-
ax.semilogy(Td, p, 'g')
241+
ax.semilogy(T, p)
242+
ax.semilogy(Td, p)
243243

244244
# An example of a slanted line at constant X
245-
l = ax.axvline(0, color='b')
245+
l = ax.axvline(0)
246246

247247
# Disables the log-formatting that comes with semilogy
248248
ax.yaxis.set_major_formatter(ScalarFormatter())

examples/lines_bars_and_markers/barh_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
performance = 3 + 10 * np.random.rand(len(people))
1414
error = np.random.rand(len(people))
1515

16-
plt.barh(y_pos, performance, xerr=error, align='center', alpha=0.4)
16+
plt.barh(y_pos, performance, xerr=error, align='center')
1717
plt.yticks(y_pos, people)
1818
plt.xlabel('Performance')
1919
plt.title('How fast do you want to go today?')

examples/lines_bars_and_markers/fill_demo.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import numpy as np
55
import matplotlib.pyplot as plt
66

7-
8-
x = np.linspace(0, 1)
7+
x = np.linspace(0, 1, 500)
98
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
109

11-
plt.fill(x, y, 'r')
10+
plt.fill(x, y)
1211
plt.grid(True)
1312
plt.show()

examples/lines_bars_and_markers/fill_demo_features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111
import matplotlib.pyplot as plt
1212

13-
x = np.linspace(0, 2 * np.pi, 100)
13+
x = np.linspace(0, 2 * np.pi, 500)
1414
y1 = np.sin(x)
1515
y2 = np.sin(3 * x)
1616
plt.fill(x, y1, 'b', x, y2, 'r', alpha=0.3)

examples/lines_bars_and_markers/line_demo_dash_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import matplotlib.pyplot as plt
99

1010

11-
x = np.linspace(0, 10)
11+
x = np.linspace(0, 10, 500)
1212
line, = plt.plot(x, np.sin(x), '--', linewidth=2)
1313

1414
dashes = [10, 5, 100, 5] # 10 points on, 5 off, 100 on, 5 off

examples/lines_bars_and_markers/line_styles_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def nice_repr(text):
2525

2626
linestyles = ['-', '--', '-.', ':']
2727
for y, linestyle in enumerate(linestyles):
28-
ax.text(-0.5, y, nice_repr(linestyle), **text_style)
28+
ax.text(-0.1, y, nice_repr(linestyle), **text_style)
2929
ax.plot(y * points, linestyle=linestyle, color=color, linewidth=3)
3030
format_axes(ax)
3131
ax.set_title('line styles')

examples/mplot3d/lorenz_attractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def lorenz(x, y, z, s=10, r=28, b=2.667):
4040
fig = plt.figure()
4141
ax = fig.gca(projection='3d')
4242

43-
ax.plot(xs, ys, zs)
43+
ax.plot(xs, ys, zs, lw=0.5)
4444
ax.set_xlabel("X Axis")
4545
ax.set_ylabel("Y Axis")
4646
ax.set_zlabel("Z Axis")

examples/mplot3d/surface3d_demo3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
colors[x, y] = colortuple[(x + y) % len(colortuple)]
2222

2323
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=colors,
24-
linewidth=0, antialiased=False)
24+
linewidth=0)
2525

2626
ax.set_zlim3d(-1, 1)
2727
ax.w_zaxis.set_major_locator(LinearLocator(6))

examples/mplot3d/trisurf3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
fig = plt.figure()
2828
ax = fig.gca(projection='3d')
2929

30-
ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.2)
30+
ax.plot_trisurf(x, y, z, linewidth=0.2, antialiased=True)
3131

3232
plt.show()

examples/pie_and_polar_charts/pie_demo_features.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
# The slices will be ordered and plotted counter-clockwise.
2222
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
2323
sizes = [15, 30, 45, 10]
24-
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
2524
explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
2625

27-
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
26+
plt.pie(sizes, explode=explode, labels=labels,
2827
autopct='%1.1f%%', shadow=True, startangle=90)
2928
# Set aspect ratio to be equal so that pie is drawn as a circle.
3029
plt.axis('equal')
@@ -33,16 +32,16 @@
3332
ax = fig.gca()
3433
import numpy as np
3534

36-
ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
35+
ax.pie(np.random.random(4), explode=explode, labels=labels,
3736
autopct='%1.1f%%', shadow=True, startangle=90,
3837
radius=0.25, center=(0, 0), frame=True)
39-
ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
38+
ax.pie(np.random.random(4), explode=explode, labels=labels,
4039
autopct='%1.1f%%', shadow=True, startangle=90,
4140
radius=0.25, center=(1, 1), frame=True)
42-
ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
41+
ax.pie(np.random.random(4), explode=explode, labels=labels,
4342
autopct='%1.1f%%', shadow=True, startangle=90,
4443
radius=0.25, center=(0, 1), frame=True)
45-
ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
44+
ax.pie(np.random.random(4), explode=explode, labels=labels,
4645
autopct='%1.1f%%', shadow=True, startangle=90,
4746
radius=0.25, center=(1, 0), frame=True)
4847

examples/pylab_examples/annotation_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
t = np.arange(0.0, 5.0, 0.01)
5050
s = np.cos(2*np.pi*t)
51-
line, = ax.plot(t, s, lw=3, color='purple')
51+
line, = ax.plot(t, s)
5252

5353
ax.annotate('axes center', xy=(.5, .5), xycoords='axes fraction',
5454
horizontalalignment='center', verticalalignment='center')
@@ -97,7 +97,7 @@
9797
ax = fig.add_subplot(111, projection='polar')
9898
r = np.arange(0, 1, 0.001)
9999
theta = 2*2*np.pi*r
100-
line, = ax.plot(theta, r, color='#ee8d18', lw=3)
100+
line, = ax.plot(theta, r)
101101

102102
ind = 800
103103
thisr, thistheta = r[ind], theta[ind]

0 commit comments

Comments
 (0)