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

Skip to content

Commit e12f264

Browse files
committed
Prefer plot() to scatter() in examples.
... when markers don't vary in size or shape. The docstring of scatter() suggests to do so (for performance), so let's showcase it.
1 parent 28e32c6 commit e12f264

File tree

8 files changed

+17
-18
lines changed

8 files changed

+17
-18
lines changed

examples/axes_grid1/scatter_hist_locatable_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
fig, axScatter = plt.subplots(figsize=(5.5, 5.5))
2121

2222
# the scatter plot:
23-
axScatter.scatter(x, y)
23+
axScatter.scatter(x, y, ".")
2424
axScatter.set_aspect(1.)
2525

2626
# create new axes on the right and on the top of the current axes

examples/axisartist/demo_floating_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ def setup_axes3(fig, rect):
149149
ax2, aux_ax2 = setup_axes2(fig, 132)
150150
theta = np.random.rand(10)*.5*np.pi
151151
radius = np.random.rand(10) + 1.
152-
aux_ax2.scatter(theta, radius)
152+
aux_ax2.plot(theta, radius, ".")
153153

154154
ax3, aux_ax3 = setup_axes3(fig, 133)
155155

156156
theta = (8 + np.random.rand(10)*(14 - 8))*15. # in degrees
157157
radius = np.random.rand(10)*14000.
158-
aux_ax3.scatter(theta, radius)
158+
aux_ax3.plot(theta, radius, ".")
159159

160160
plt.show()

examples/images_contours_and_fields/quiver_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
pivot='mid', units='inches')
3636
qk = ax2.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E',
3737
coordinates='figure')
38-
ax2.scatter(X[::3, ::3], Y[::3, ::3], color='r', s=5)
38+
ax2.plot(X[::3, ::3], Y[::3, ::3], '.', ms=3, c='r')
3939

4040
###############################################################################
4141

@@ -48,7 +48,7 @@
4848
scale=1 / 0.15)
4949
qk = ax3.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E',
5050
coordinates='figure')
51-
ax3.scatter(X, Y, color='0.5', s=1)
51+
ax3.plot(X, Y, '.', color='0.5', ms=3)
5252

5353
plt.show()
5454

examples/lines_bars_and_markers/scatter_star_poly.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
Scatter Star Poly
44
=================
55
6-
Create multiple scatter plots with different
7-
star symbols.
8-
6+
Create multiple scatter plots with different star symbols.
97
"""
8+
109
import numpy as np
1110
import matplotlib.pyplot as plt
1211

examples/statistics/confidence_ellipse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ def get_correlated_dataset(n, dependency, mu, scale):
142142
fig, axs = plt.subplots(1, 3, figsize=(9, 3))
143143
for ax, (title, dependency) in zip(axs, PARAMETERS.items()):
144144
x, y = get_correlated_dataset(800, dependency, mu, scale)
145-
ax.scatter(x, y, s=0.5)
145+
ax.plot(x, y, ".", ms=1)
146146

147147
ax.axvline(c='grey', lw=1)
148148
ax.axhline(c='grey', lw=1)
149149

150150
confidence_ellipse(x, y, ax, edgecolor='red')
151151

152-
ax.scatter(mu[0], mu[1], c='red', s=3)
152+
ax.plot(mu[0], mu[1], ".", ms=1, c="r")
153153
ax.set_title(title)
154154

155155
plt.show()
@@ -175,7 +175,7 @@ def get_correlated_dataset(n, dependency, mu, scale):
175175
ax_nstd.axhline(c='grey', lw=1)
176176

177177
x, y = get_correlated_dataset(500, dependency_nstd, mu, scale)
178-
ax_nstd.scatter(x, y, s=0.5)
178+
ax_nstd.plot(x, y, ".", ms=1)
179179

180180
confidence_ellipse(x, y, ax_nstd, n_std=1,
181181
label=r'$1\sigma$', edgecolor='firebrick')
@@ -184,7 +184,7 @@ def get_correlated_dataset(n, dependency, mu, scale):
184184
confidence_ellipse(x, y, ax_nstd, n_std=3,
185185
label=r'$3\sigma$', edgecolor='blue', linestyle=':')
186186

187-
ax_nstd.scatter(mu[0], mu[1], c='red', s=3)
187+
ax_nstd.plot(mu[0], mu[1], ".", ms=1, c="r")
188188
ax_nstd.set_title('Different standard deviations')
189189
ax_nstd.legend()
190190
plt.show()
@@ -215,8 +215,8 @@ def get_correlated_dataset(n, dependency, mu, scale):
215215
confidence_ellipse(x, y, ax_kwargs,
216216
alpha=0.5, facecolor='pink', edgecolor='purple', zorder=0)
217217

218-
ax_kwargs.scatter(x, y, s=0.5)
219-
ax_kwargs.scatter(mu[0], mu[1], c='red', s=3)
218+
ax_kwargs.plot(x, y, ".", ms=1)
219+
ax_kwargs.plot(mu[0], mu[1], ".", ms=1, c="r")
220220
ax_kwargs.set_title(f'Using kwargs')
221221

222222
fig.subplots_adjust(hspace=0.25)

examples/statistics/customized_violin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def set_axis_style(ax, labels):
6363
whiskersMin, whiskersMax = whiskers[:, 0], whiskers[:, 1]
6464

6565
inds = np.arange(1, len(medians) + 1)
66-
ax2.scatter(inds, medians, marker='o', color='white', s=30, zorder=3)
66+
ax2.plot(inds, medians, 'o', color='white', zorder=3)
6767
ax2.vlines(inds, quartile1, quartile3, color='k', linestyle='-', lw=5)
6868
ax2.vlines(inds, whiskersMin, whiskersMax, color='k', linestyle='-', lw=1)
6969

examples/text_labels_and_annotations/text_rotation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def addtext(ax, props):
2929
ax.text(3.5, 0.5, 'text 225', props, rotation=225)
3030
ax.text(4.5, 0.5, 'text -45', props, rotation=-45)
3131
for x in range(0, 5):
32-
ax.scatter(x + 0.5, 0.5, color='r', alpha=0.5)
32+
ax.plot(x + 0.5, 0.5, 'ro', alpha=0.5)
3333
ax.set_yticks([0, .5, 1])
3434
ax.set_xlim(0, 5)
3535
ax.grid(True)

examples/userdemo/annotate_text_arrow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
x2 = 1. + np.random.randn(100)
1717
y2 = 1. + np.random.randn(100)
1818

19-
ax.scatter(x1, y1, color="r")
20-
ax.scatter(x2, y2, color="g")
19+
ax.plot(x1, y1, ".", c="r")
20+
ax.plot(x2, y2, ".", c="g")
2121

2222
bbox_props = dict(boxstyle="round", fc="w", ec="0.5", alpha=0.9)
2323
ax.text(-2, -2, "Sample A", ha="center", va="center", size=20,

0 commit comments

Comments
 (0)