8000 Merge remote-tracking branch 'upstream/master' · matplotlib/matplotlib@2c5a873 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c5a873

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents b2ca609 + e285dde commit 2c5a873

Some content is hidden

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

57 10000 files changed

+525
-420
lines changed

.flake8

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ ignore =
1010
F401, F403, F811, F841,
1111
# Some new flake8 ignores:
1212
N801, N802, N803, N806, N812,
13+
# pydocstyle
14+
D100, D101, D102, D103, D104, D105, D106, D107,
15+
D200, D202, D203, D204, D205, D207, D208, D209,
16+
D210, D211, D212, D213, D214, D215,
17+
D300, D301, D302,
18+
D400, D401, D402, D403, D404, D405, D406, D407, D408, D409,
19+
D410, D411, D412, D413, D414,
1320

1421
exclude =
1522
.git
@@ -137,6 +144,7 @@ per-file-ignores =
137144
examples/images_contours_and_fields/triplot_demo.py: E201, E402
138145
examples/images_contours_and_fields/watermark_image.py: E402
139146
examples/lines_bars_and_markers/errorbar_limits_simple.py: E402
147+
examples/lines_bars_and_markers/fill.py: E402
140148
examples/lines_bars_and_markers/fill_between_demo.py: E402
141149
examples/lines_bars_and_markers/filled_step.py: E402
142150
examples/lines_bars_and_markers/joinstyle.py: E402

doc/_static/yellowbrick.png

66.1 KB
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deprecations
2+
````````````
3+
4+
``FigureCanvasBase.draw_cursor`` (which has never done anything and has never
5+
been overridden in any backend) is deprecated.

doc/thirdpartypackages/index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ Windrose
160160
Numpy library to manage wind data, draw windroses (also known as polar rose
161161
plots), draw probability density functions and fit Weibull distributions.
162162

163+
Yellowbrick
164+
===========
165+
`Yellowbrick <https://www.scikit-yb.org/>`_ is a suite of visual diagnostic tools for machine learning that enables human steering of the model selection process. Yellowbrick combines scikit-learn with matplotlib using an estimator-based API called the ``Visualizer``, which wraps both sklearn models and matplotlib Axes. ``Visualizer`` objects fit neatly into the machine learning workflow allowing data scientists to integrate visual diagnostic and model interpretation tools into experimentation without extra steps.
166+
167+
.. image:: /_static/yellowbrick.png
168+
:height: 400px
169+
163170

164171
Interactivity
165172
*************
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Errorbar plots can shift which points have error bars
2+
-----------------------------------------------------
3+
4+
Previously, `plt.errorbar()` accepted a kwarg `errorevery` such that the
5+
command `plt.errorbar(x, y, yerr, errorevery=6)` would add error bars to
6+
datapoints `x[::6], y[::6]`.
7+
8+
`errorbar()` now also accepts a tuple for `errorevery` such that
9+
`plt.errorbar(x, y, yerr, errorevery=(start, N))` adds error bars to points
10+
`x[start::N], y[start::N]`.

examples/animation/animate_decay.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
import matplotlib.animation as animation
1414

1515

16-
def data_gen(t=0):
17-
cnt = 0
18-
while cnt < 1000:
19-
cnt += 1
20-
t += 0.1
16+
def data_gen():
17+
for cnt in range(1000):
18+
t = cnt / 10
2119
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
2220

2321

examples/images_contours_and_fields/quiver_demo.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
"""
2-
========================================================
3-
Demonstration of advanced quiver and quiverkey functions
4-
========================================================
2+
=======================================
3+
Advanced quiver and quiverkey functions
4+
=======================================
55
66
Demonstrates some more advanced options for `~.axes.Axes.quiver`. For a simple
77
example refer to :doc:`/gallery/images_contours_and_fields/quiver_simple_demo`.
88
9-
Known problem: the plot autoscaling does not take into account the arrows, so
10-
those on the boundaries are often out of the picture. This is *not* an easy
11-
problem to solve in a perfectly general way. The workaround is to manually
12-
expand the Axes objects.
9+
Note: The plot autoscaling does not take into account the arrows, so
10+
those on the boundaries may reach out of the picture. This is not an easy
11+
problem to solve in a perfectly general way. The recommended workaround is to
12+
manually set the Axes limits in such a case.
1313
"""
14+
1415
import matplotlib.pyplot as plt
1516
import numpy as np
1617

@@ -38,14 +39,16 @@
3839

3940
###############################################################################
4041

42+
# sphinx_gallery_thumbnail_number = 3
43+
4144
fig3, ax3 = plt.subplots()
4245
ax3.set_title("pivot='tip'; scales with x view")
4346
M = np.hypot(U, V)
4447
Q = ax3.quiver(X, Y, U, V, M, units='x', pivot='tip', width=0.022,
4548
scale=1 / 0.15)
4649
qk = ax3.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E',
4750
coordinates='figure')
48-
ax3.scatter(X, Y, color='k', s=5)
51+
ax3.scatter(X, Y, color='0.5', s=1)
4952

5053
plt.show()
5154

examples/lines_bars_and_markers/bar_stacked.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,28 @@
77
using `~matplotlib.pyplot.bar`. Note the parameters *yerr* used for
88
error bars, and *bottom* to stack the women's bars on top of the men's
99
bars.
10-
1110
"""
1211

1312
import numpy as np
1413
import matplotlib.pyplot as plt
1514

1615

1716
N = 5
18-
menMeans = (20, 35, 30, 35, 27)
19-
womenMeans = (25, 32, 34, 20, 25)
20-
menStd = (2, 3, 4, 1, 2)
21-
womenStd = (3, 5, 2, 3, 3)
17+
men_means = [20, 35, 30, 35, 27]
18+
women_means = [25, 32, 34, 20, 25]
19+
men_std = [2, 3, 4, 1, 2]
20+
women_std = [3, 5, 2, 3, 3]
2221
ind = np.arange(N) # the x locations for the groups
2322
width = 0.35 # the width of the bars: can also be len(x) sequence
2423

25-
p1 = plt.bar(ind, menMeans, width, yerr=menStd)
26-
p2 = plt.bar(ind, womenMeans, width,
27-
bottom=menMeans, yerr=womenStd)
24+
plt.bar(ind, men_means, width, yerr=men_std, label='Men')
25+
plt.bar(ind, women_means, width, yerr=women_std, bottom=men_means,
26+
label='Women')
2827

2928
plt.ylabel('Scores')
3029
plt.title('Scores by group and gender')
3130
plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
3231
plt.yticks(np.arange(0, 81, 10))
33-
plt.legend((p1[0], p2[0]), ('Men', 'Women'))
32+
plt.legend()
3433

3534
plt.show()

examples/lines_bars_and_markers/errorbar_subsample.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,29 @@
1212

1313
# example data
1414
x = np.arange(0.1, 4, 0.1)
15-
y = np.exp(-x)
15+
y1 = np.exp(-1.0 * x)
16+
y2 = np.exp(-0.5 * x)
1617

1718
# example variable error bar values
18-
yerr = 0.1 + 0.1 * np.sqrt(x)
19+
y1err = 0.1 + 0.1 * np.sqrt(x)
20+
y2err = 0.1 + 0.1 * np.sqrt(x/2)
1921

2022

2123
# Now switch to a more OO interface to exercise more features.
22-
fig, axs = plt.subplots(nrows=1, ncols=2, sharex=True)
23-
ax = axs[0]
24-
ax.errorbar(x, y, yerr=yerr)
25-
ax.set_title('all errorbars')
24+
fig, (ax_l, ax_c, ax_r) = plt.subplots(nrows=1, ncols=3,
25+
sharex=True, figsize=(12, 6))
2626

27-
ax = axs[1]
28-
ax.errorbar(x, y, yerr=yerr, errorevery=5)
29-
ax.set_title('only every 5th errorbar')
27+
ax_l.set_title('all errorbars')
28+
ax_l.errorbar(x, y1, yerr=y1err)
29+
ax_l.errorbar(x, y2, yerr=y2err)
3030

31+
ax_c.set_title('only every 6th errorbar')
32+
ax_c.errorbar(x, y1, yerr=y1err, errorevery=6)
33+
ax_c.errorbar(x, y2, yerr=y2err, errorevery=6)
3134

32-
fig.suptitle('Errorbar subsampling for better appearance')
35+
ax_r.set_title('second series shifted by 3')
36+
ax_r.errorbar(x, y1, yerr=y1err, errorevery=(0, 6))
37+
ax_r.errorbar(x, y2, yerr=y2err, errorevery=(3, 6))
3338

39+
fig.suptitle('Errorbar subsampling for better appearance')
3440
plt.show()
Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,93 @@
11
"""
22
==============
3-
Fill plot demo
3+
Filled polygon
44
==============
55
6-
Demo fill plot.
6+
`~.Axes.fill()` draws a filled polygon based based on lists of point
7+
coordinates *x*, *y*.
8+
9+
This example uses the `Koch snowflake`_ as an example polygon.
10+
11+
.. _Koch snowflake: https://en.wikipedia.org/wiki/Koch_snowflake
12+
713
"""
814

9-
###############################################################################
10-
# First, the most basic fill plot a user can make with matplotlib:
1115
import numpy as np
1216
import matplotlib.pyplot as plt
1317

14-
x = [0, 1, 2, 1]
15-
y = [1, 2, 1, 0]
1618

17-
fig, ax = plt.subplots()
18-
ax.fill(x, y)
19-
plt.show()
19+
def koch_snowflake(order, scale=10):
20+
"""
21+
Return two lists x, y of point coordinates of the Koch snowflake.
22+
23+
Arguments
24+
---------
< C2EE /td>
25+
order : int
26+
The recursion depth.
27+
scale : float
28+
The extent of the snowflake (edge length of the base triangle).
29+
"""
30+
def _koch_snowflake_complex(order):
31+
if order == 0:
32+
# initial triangle
33+
angles = np.array([0, 120, 240]) + 90
34+
return scale / np.sqrt(3) * np.exp(np.deg2rad(angles) * 1j)
35+
else:
36+
ZR = 0.5 - 0.5j * np.sqrt(3) / 3
37+
38+
p1 = _koch_snowflake_complex(order - 1) # start points
39+
p2 = np.roll(p1, shift=-1) # end points
40+
dp = p2 - p1 # connection vectors
41+
42+
new_points = np.empty(len(p1) * 4, dtype=np.complex128)
43+
new_points[::4] = p1
44+
new_points[1::4] = p1 + dp / 3
45+
new_points[2::4] = p1 + dp * ZR
46+
new_points[3::4] = p1 + dp / 3 * 2
47+
return new_points
48+
49+
points = _koch_snowflake_complex(order)
50+
x, y = points.real, points.imag
51+
return x, y
52+
2053

2154
###############################################################################
22-
# Next, a few more optional features:
23-
#
24-
# * Multiple curves with a single command.
25-
# * Setting the fill color.
26-
# * Setting the opacity (alpha value).
55+
# Basic usage:
2756

57+
x, y = koch_snowflake(order=5)
2858

29-
x = np.linspace(0, 1.5 * np.pi, 500)
30-
y1 = np.sin(x)
31-
y2 = np.sin(3 * x)
59+
plt.figure(figsize=(8, 8))
60+
plt.axis('equal')
61+
plt.fill(x, y)
62+
plt.show()
3263

33-
fig, ax = plt.subplots()
64+
###############################################################################
65+
# Use keyword arguments *facecolor* and *edgecolor* to modify the the colors
66+
# of the polygon. Since the *linewidth* of the edge is 0 in the default
67+
# Matplotlib style, we have to set it as well for the edge to become visible.
3468

35-
ax.fill(x, y1, 'b', x, y2, 'r', alpha=0.3)
69+
x, y = koch_snowflake(order=2)
3670

37-
# Outline of the region we've filled in
38-
ax.plot(x, y1, c='b', alpha=0.8)
39-
ax.plot(x, y2, c='r', alpha=0.8)
40-
ax.plot([x[0], x[-1]], [y1[0], y1[-1]], c='b', alpha=0.8)
41-
ax.plot([x[0], x[-1]], [y2[0], y2[-1]], c='r', alpha=0.8)
71+
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(9, 3),
72+
subplot_kw={'aspect': 'equal'})
73+
ax1.fill(x, y)
74+
ax2.fill(x, y, facecolor='lightsalmon', edgecolor='orangered', linewidth=3)
75+
ax3.fill(x, y, facecolor='none', edgecolor='purple', linewidth=3)
4276

4377
plt.show()
78+
79+
#############################################################################
80+
#
81+
# ------------
82+
#
83+
# References
84+
# """"""""""
85+
#
86+
# The use of the following functions, methods, classes and modules is shown
87+
# in this example:
88+
89+
import matplotlib
90+
matplotlib.axes.Axes.fill
91+
matplotlib.pyplot.fill
92+
matplotlib.axes.Axes.axis
93+
matplotlib.pyplot.axis
Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,54 @@
11
"""
2-
============
3-
Scatter Hist
4-
============
5-
6-
Creates histogram from scatter plot
7-
and adds them to the sides of the plot.
2+
============================
3+
Scatter plot with histograms
4+
============================
85
6+
Create a scatter plot with histograms to its sides.
97
"""
108
import numpy as np
119
import matplotlib.pyplot as plt
12-
from matplotlib.ticker import NullFormatter
1310

1411
# Fixing random state for reproducibility
1512
np.random.seed(19680801)
1613

17-
1814
# the random data
1915
x = np.random.randn(1000)
2016
y = np.random.randn(1000)
2117

22-
nullfmt = NullFormatter() # no labels
23-
2418
# definitions for the axes
2519
left, width = 0.1, 0.65
2620
bottom, height = 0.1, 0.65
27-
bottom_h = left_h = left + width + 0.02
21+
spacing = 0.005
22+
2823

2924
rect_scatter = [left, bottom, width, height]
30-
rect_histx = [left, bottom_h, width, 0.2]
31-
rect_histy = [left_h, bottom, 0.2, height]
25+
rect_histx = [left, bottom + height + spacing, width, 0.2]
26+
rect_histy = [left + width + spacing, bottom, 0.2, height]
3227

3328
# start with a rectangular Figure
3429
plt.figure(figsize=(8, 8))
3530

36-
axScatter = plt.axes(rect_scatter)
37-
axHistx = plt.axes(rect_histx)
38-
axHisty = plt.axes(rect_histy)
39-
40-
# no labels
41-
axHistx.xaxis.set_major_formatter(nullfmt)
42-
axHisty.yaxis.set_major_formatter(nullfmt)
31+
ax_scatter = plt.axes(rect_scatter)
32+
ax_scatter.tick_params(direction='in', top=True, right=True)
33+
ax_histx = plt.axes(rect_histx)
34+
ax_histx.tick_params(direction='in', labelbottom=False)
35+
ax_histy = plt.axes(rect_histy)
36+
ax_histy.tick_params(direction='in', labelleft=False)
4337

4438
# the scatter plot:
45-
axScatter.scatter(x, y)
39+
ax_scatter.scatter(x, y)
4640

4741
# now determine nice limits by hand:
4842
binwidth = 0.25
49-
xymax = max(np.max(np.abs(x)), np.max(np.abs(y)))
50-
lim = (int(xymax/binwidth) + 1) * binwidth
51-
52-
axScatter.set_xlim((-lim, lim))
53-
axScatter.set_ylim((-lim, lim))
43+
lim = np.ceil(np.abs([x, y]).max() / binwidth) * binwidth
44+
ax_scatter.set_xlim((-lim, lim))
45+
ax_scatter.set_ylim((-lim, lim))
5446

5547
bins = np.arange(-lim, lim + binwidth, binwidth)
56-
axHistx.hist(x, bins=bins)
57-
axHisty.hist(y, bins=bins, orientation='horizontal')
48+
ax_histx.hist(x, bins=bins)
49+
ax_histy.hist(y, bins=bins, orientation='horizontal')
5850

59-
axHistx.set_xlim(axScatter.get_xlim())
60-
axHisty.set_ylim(axScatter.get_ylim())
51+
ax_histx.set_xlim(ax_scatter.get_xlim())
52+
ax_histy.set_ylim(ax_scatter.get_ylim())
6153

6254
plt.show()

0 commit comments

Comments
 (0)
0