Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions plot_types/arrays/contourf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

# make data
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
Z = (1 - X/2. + X**5 + Y**3)*np.exp(-X**2-Y**2)
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)
Z = Z - Z.min()
levs = np.linspace(np.min(Z), np.max(Z), 7)
levels = np.linspace(np.min(Z), np.max(Z), 7)

# plot
fig, ax = plt.subplots()

plt.contourf(X, Y, Z, levels=levs)
plt.contour(X, Y, Z, levels=levs, colors="white", linewidths=0.5)
ax.contourf(X, Y, Z, levels=levels)
ax.contour(X, Y, Z, levels=levels, colors="white", linewidths=0.5)

plt.show()
6 changes: 2 additions & 4 deletions plot_types/arrays/imshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@

# plot
fig, ax = plt.subplots()
ax.grid(False)

ax.imshow(Z, extent=[0, 8, 0, 8], interpolation="nearest",
cmap=plt.get_cmap('Blues'), vmin=0, vmax=1.6)

ax.set(xticks=[], yticks=[])
ax.imshow(Z)

plt.show()
3 changes: 2 additions & 1 deletion plot_types/arrays/pcolormesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

# plot
fig, ax = plt.subplots()
ax.grid(False)

ax.pcolormesh(X, Y, Z, vmin=0, vmax=1.5, shading='nearest')
ax.pcolormesh(X, Y, Z, vmin=0, vmax=1.5)

plt.show()
10 changes: 5 additions & 5 deletions plot_types/arrays/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
plt.style.use('mpl_plot_gallery')

# make data
T = np.linspace(0, 2*np.pi, 8)
X, Y = 4 + 1 * np.cos(T), 4 + 1 * np.sin(T)
U, V = 1.5 * np.cos(T), 1.5 * np.sin(T)
phi = np.linspace(0, 2 * np.pi, 8)
x, y = 4 + 1 * np.cos(phi), 4 + 1 * np.sin(phi)
u, v = 1.5 * np.cos(phi), 1.5 * np.sin(phi)

# plot
fig, ax = plt.subplots()

plt.quiver(X, Y, U, V, color="C0", angles='xy',
scale_units='xy', scale=0.5, width=.05)
ax.quiver(x, y, u, v, color="C0", angles='xy',
scale_units='xy', scale=0.5, width=.05)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
Expand Down
6 changes: 3 additions & 3 deletions plot_types/basic/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

# make data:
np.random.seed(3)
X = 0.5 + np.arange(8)
Y = np.random.uniform(2, 7, len(X))
x = 0.5 + np.arange(8)
y = np.random.uniform(2, 7, len(x))

# plot
fig, ax = plt.subplots()

ax.bar(X, Y, width=1, edgecolor="white", linewidth=0.7)
ax.bar(x, y, width=1, edgecolor="white", linewidth=0.7)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
Expand Down
6 changes: 3 additions & 3 deletions plot_types/basic/pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@


# make data
X = [1, 2, 3, 4]
colors = plt.get_cmap('Blues')(np.linspace(0.2, 0.7, len(X)))
x = [1, 2, 3, 4]
colors = plt.get_cmap('Blues')(np.linspace(0.2, 0.7, len(x)))

# plot
fig, ax = plt.subplots()
ax.pie(X, colors=colors, radius=3, center=(4, 4),
ax.pie(x, colors=colors, radius=3, center=(4, 4),
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
Expand Down
6 changes: 3 additions & 3 deletions plot_types/basic/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
plt.style.use('mpl_plot_gallery')

# make data
X = np.linspace(0, 10, 100)
Y = 4 + 2 * np.sin(2 * X)
x = np.linspace(0, 10, 100)
y = 4 + 2 * np.sin(2 * x)

# plot
fig, ax = plt.subplots()

ax.plot(X, Y, linewidth=2.0)
ax.plot(x, y, linewidth=2.0)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
Expand Down
9 changes: 5 additions & 4 deletions plot_types/basic/scatter_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@

# make the data
np.random.seed(3)
X = 4 + np.random.normal(0, 2, 24)
Y = 4 + np.random.normal(0, 2, len(X))
x = 4 + np.random.normal(0, 2, 24)
y = 4 + np.random.normal(0, 2, len(x))
# size and color:
S = np.random.uniform(15, 80, len(X))
sizes = np.random.uniform(15, 80, len(x))
colors = np.random.uniform(15, 80, len(x))

# plot
fig, ax = plt.subplots()

ax.scatter(X, Y, s=S, c=-S, cmap=plt.get_cmap('Blues'), vmin=-100, vmax=0)
ax.scatter(x, y, s=sizes, c=colors, vmin=-100, vmax=0)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
Expand Down
6 changes: 3 additions & 3 deletions plot_types/basic/stem.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

# make data
np.random.seed(3)
X = 0.5 + np.arange(8)
Y = np.random.uniform(2, 7, len(X))
x = 0.5 + np.arange(8)
y = np.random.uniform(2, 7, len(x))

# plot
fig, ax = plt.subplots()

ax.stem(X, Y, bottom=0, linefmt="-", markerfmt="d")
ax.stem(x, y)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
Expand Down
6 changes: 3 additions & 3 deletions plot_types/basic/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

# make data
np.random.seed(3)
X = 0.5 + np.arange(8)
Y = np.random.uniform(2, 7, len(X))
x = 0.5 + np.arange(8)
y = np.random.uniform(2, 7, len(x))

# plot
fig, ax = plt.subplots()

ax.step(X, Y, linewidth=2.5)
ax.step(x, y, linewidth=2.5)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
Expand Down
7 changes: 3 additions & 4 deletions plot_types/stats/barbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
np.random.seed(1)
X = [[2, 4, 6]]
Y = [[1.5, 3, 2]]
U = -np.ones((1, 3)) * 0
V = -np.ones((1, 3)) * np.linspace(50, 100, 3)
U = np.zeros_like(X)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was made lowercase everywhere else. Why uppercase here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly follow the capitalization in the signature of the respective plot function, some of which are lowercase, some are uppercase.

There's a loose convention that 1D arrays have regular lowercase names and 2D arrays from np.meshgrid() have uppercase names (e.g. X, Y = np.meshgrid(x, y)). I suspect that the signature roughly follows this pattern: If we expect 2D input, we use an uppercase parameter name. For barbs this is a bit ambiguous as parameters can be 1D or 2D, so I followed the signature style.

V = -np.ones_like(X) * np.linspace(50, 100, 3)
Comment on lines 15 to +18
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lower case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment in #20509 (review)


# plot:
fig, ax = plt.subplots()

ax.barbs(X, Y, U, V, barbcolor="C0", flagcolor="C0",
length=10, linewidth=1.5)
ax.barbs(X, Y, U, V, barbcolor="C0", flagcolor="C0", length=10, linewidth=1.5)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
Expand Down
10 changes: 5 additions & 5 deletions plot_types/stats/errorbar_plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
==========================
errorbar(X, Y, xerr, yerr)
errorbar(x, y, yerr, xerr)
==========================

See `~matplotlib.axes.Axes.errorbar`.
Expand All @@ -12,14 +12,14 @@

# make data:
np.random.seed(1)
X = [2, 4, 6]
Y = [4, 5, 4]
E = np.random.uniform(0.5, 1.5, 3)
x = [2, 4, 6]
y = [4, 5, 4]
yerr = np.random.uniform(0.5, 1.5, 3)

# plot:
fig, ax = plt.subplots()

ax.errorbar(X, Y, E, linewidth=2, capsize=6)
ax.errorbar(x, y, yerr, linewidth=2, capsize=6)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
Expand Down
4 changes: 2 additions & 2 deletions plot_types/stats/eventplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

# make data:
np.random.seed(1)
X = [2, 4, 6]
x = [2, 4, 6]
D = np.random.gamma(4, size=(3, 50))

# plot:
fig, ax = plt.subplots()

ax.eventplot(D, orientation="vertical", lineoffsets=X, linewidth=0.75)
ax.eventplot(D, orientation="vertical", lineoffsets=x, linewidth=0.75)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
Expand Down
2 changes: 1 addition & 1 deletion plot_types/stats/hexbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# make data: correlated + noise
np.random.seed(1)
x = np.random.randn(5000)
y = 1.2 * x + np.random.randn(5000)/3
y = 1.2 * x + np.random.randn(5000) / 3

# plot:
fig, ax = plt.subplots()
Expand Down
2 changes: 1 addition & 1 deletion plot_types/stats/hist2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# make data: correlated + noise
np.random.seed(1)
x = np.random.randn(5000)
y = 1.2 * x + np.random.randn(5000)/3
y = 1.2 * x + np.random.randn(5000) / 3

# plot:
fig, ax = plt.subplots()
Expand Down
6 changes: 3 additions & 3 deletions plot_types/stats/hist_plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
=======
hist(X)
hist(x)
=======

See `~matplotlib.axes.Axes.hist`.
Expand All @@ -12,12 +12,12 @@

# make data
np.random.seed(1)
X = 4 + np.random.normal(0, 1.5, 200)
x = 4 + np.random.normal(0, 1.5, 200)

# plot:
fig, ax = plt.subplots()

ax.hist(X, bins=8, linewidth=0.5, edgecolor="white")
ax.hist(x, bins=8, linewidth=0.5, edgecolor="white")

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
Expand Down
6 changes: 3 additions & 3 deletions plot_types/stats/violin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
# plot:
fig, ax = plt.subplots()

VP = ax.violinplot(D, [2, 4, 6], widths=2,
showmeans=False, showmedians=False, showextrema=False)
vp = ax.violinplot(D, [2, 4, 6], widths=2,
showmeans=False, showmedians=False, showextrema=False)
# styling:
for body in VP['bodies']:
for body in vp['bodies']:
body.set_alpha(0.9)
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
Expand Down
10 changes: 5 additions & 5 deletions plot_types/unstructured/tricontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

# make structured data
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
Z = (1 - X/2. + X**5 + Y**3)*np.exp(-X**2-Y**2)
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)
Z = Z - Z.min()

# sample it to make unstructured x, y, z
np.random.seed(1)
ysamp = np.random.randint(0, high=256, size=250)
xsamp = np.random.randint(0, high=256, size=250)
ysamp = np.random.randint(0, 256, size=250)
xsamp = np.random.randint(0, 256, size=250)
y = Y[:, 0][ysamp]
x = X[0, :][xsamp]
z = Z[ysamp, xsamp]
Expand All @@ -27,8 +27,8 @@
fig, ax = plt.subplots()

ax.plot(x, y, '.k', alpha=0.5)
levs = np.linspace(np.min(Z), np.max(Z), 7)
ax.tricontourf(x, y, z, levels=levs)
levels = np.linspace(np.min(Z), np.max(Z), 7)
ax.tricontourf(x, y, z, levels=levels)

ax.set(xlim=(-3, 3), ylim=(-3, 3))

Expand Down
4 changes: 2 additions & 2 deletions plot_types/unstructured/tripcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

# sample it to make unstructured x, y, z
np.random.seed(1)
ysamp = np.random.randint(0, high=256, size=250)
xsamp = np.random.randint(0, high=256, size=250)
ysamp = np.random.randint(0, 256, size=250)
xsamp = np.random.randint(0, 256, size=250)
y = Y[:, 0][ysamp]
x = X[0, :][xsamp]
z = Z[ysamp, xsamp]
Expand Down
4 changes: 2 additions & 2 deletions plot_types/unstructured/triplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

# sample it to make x, y, z
np.random.seed(1)
ysamp = np.random.randint(0, high=256, size=250)
xsamp = np.random.randint(0, high=256, size=250)
ysamp = np.random.randint(0, 256, size=250)
xsamp = np.random.randint(0, 256, size=250)
y = Y[:, 0][ysamp]
x = X[0, :][xsamp]

Expand Down