8000 Move some examples out of pylab_examples by dstansby · Pull Request #8633 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Move some examples out of pylab_examples #8633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Move some pylab examples to other folders
PEP8 moved examples

Move subplots and scatter examples

PEP8 scatter examples

Small example fixes

Remove old barchart demos

Add new barchart demo back
  • Loading branch information
dstansby committed May 24, 2017
commit d70af4c40d4f81c98e34b834f706ef73ae4fb4b5
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""
===============
Color By Yvalue
===============
================
Color By y-value
================

Use masked arrays to plot a line with different colors by y-value.
"""
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)
s = np.sin(2 * np.pi * t)

upper = 0.77
lower = -0.77
Expand All @@ -19,5 +19,6 @@
slower = np.ma.masked_where(s > lower, s)
smiddle = np.ma.masked_where(np.logical_or(s < lower, s > upper), s)

plt.plot(t, smiddle, t, slower, t, supper)
fig, ax = plt.subplots()
ax.plot(t, smiddle, t, slower, t, supper)
plt.show()
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
import matplotlib.pyplot as plt
import numpy as np

plt.subplot(111, facecolor='darkslategray')
#subplot(111, facecolor='#ababab')
t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)
plt.plot(t, s, 'C1')
plt.xlabel('time (s)', color='C1')
plt.ylabel('voltage (mV)', color='0.5') # grayscale color
plt.title('About as silly as it gets, folks', color='#afeeee')
s = np.sin(2 * np.pi * t)

fig, ax = plt.subplots(facecolor='darkslategray')
ax.plot(t, s, 'C1')
ax.set_xlabel('time (s)', color='C1')
ax.set_ylabel('voltage (mV)', color='0.5') # grayscale color
ax.set_title('About as silly as it gets, folks', color='#afeeee')

plt.show()
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Data to plot.
x, y = np.meshgrid(np.arange(7), np.arange(10))
z = np.sin(0.5*x)*np.cos(0.52*y)
z = np.sin(0.5 * x) * np.cos(0.52 * y)

# Mask various z values.
mask = np.zeros_like(z, dtype=np.bool)
Expand All @@ -24,7 +24,7 @@

corner_masks = [False, True]
for i, corner_mask in enumerate(corner_masks):
plt.subplot(1, 2, i+1)
plt.subplot(1, 2, i + 1)
cs = plt.contourf(x, y, z, corner_mask=corner_mask)
plt.contour(cs, colors='k')
plt.title('corner_mask = {0}'.format(corner_mask))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@

"""
import matplotlib.pyplot as plt
from numpy import arange, pi, cos, sin
from numpy.random import rand
import numpy as np

# unit area ellipse
rx, ry = 3., 1.
area = rx * ry * pi
theta = arange(0, 2*pi + 0.01, 0.1)
verts = list(zip(rx/area*cos(theta), ry/area*sin(theta)))
area = rx * ry * np.pi
theta = np.arange(0, 2 * np.pi + 0.01, 0.1)
verts = list(zip(rx / area * np.cos(theta), ry / area * np.sin(theta)))

x, y, s, c = rand(4, 30)
x, y, s, c = np.random.rand(4, 30)
s *= 10**2.

fig, ax = plt.subplots()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
price_data = np.load(datafile)['price_data'].view(np.recarray)
price_data = price_data[-250:] # get the most recent 250 trading days

delta1 = np.diff(price_data.adj_close)/price_data.adj_close[:-1]
delta1 = np.diff(price_data.adj_close) / price_data.adj_close[:-1]

# Marker size in units of points^2
volume = (15 * price_data.volume[:-2] / price_data.volume[0])**2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

N = 100
r0 = 0.6
x = 0.9*np.random.rand(N)
y = 0.9*np.random.rand(N)
area = np.pi*(10 * np.random.rand(N))**2 # 0 to 10 point radii
x = 0.9 * np.random.rand(N)
y = 0.9 * np.random.rand(N)
area = np.pi * (10 * np.random.rand(N))**2 # 0 to 10 point radii
c = np.sqrt(area)
r = np.sqrt(x*x + y*y)
r = np.sqrt(x * x + y * y)
area1 = np.ma.masked_where(r < r0, area)
area2 = np.ma.masked_where(r >= r0, area)
plt.scatter(x, y, s=area1, marker='^', c=c)
plt.scatter(x, y, s=area2, marker='o', c=c)
# Show the boundary between the regions:
theta = np.arange(0, np.pi/2, 0.01)
plt.plot(r0*np.cos(theta), r0*np.sin(theta))
theta = np.arange(0, np.pi / 2, 0.01)
plt.plot(r0 * np.cos(theta), r0 * np.sin(theta))

plt.show()
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

for N in (20, 100, 1000, 10000, 50000):
tstart = time.time()
x = 0.9*np.random.rand(N)
y = 0.9*np.random.rand(N)
s = 20*np.random.rand(N)
x = 0.9 * np.random.rand(N)
y = 0.9 * np.random.rand(N)
s = 20 * np.random.rand(N)
plt.scatter(x, y, s)
print('%d symbols in %1.2f s' % (N, time.time() - tstart))
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
plt.subplot(323)
plt.scatter(x, y, s=80, c=z, marker=(verts, 0))
# equivalent:
#plt.scatter(x,y,s=80, c=z, marker=None, verts=verts)
# plt.scatter(x, y, s=80, c=z, marker=None, verts=verts)

plt.subplot(324)
plt.scatter(x, y, s=80, c=z, marker=(5, 1))
Expand Down
13 changes: 0 additions & 13 deletions examples/pylab_examples/README

This file was deleted.

12 changes: 6 additions & 6 deletions examples/pylab_examples/barb_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

x = np.linspace(-5, 5, 5)
X, Y = np.meshgrid(x, x)
U, V = 12*X, 12*Y
U, V = 12 * X, 12 * Y

data = [(-1.5, .5, -6, -6),
(1, -1, -46, 46),
Expand All @@ -27,29 +27,29 @@
ax.barbs(X, Y, U, V)

# Arbitrary set of vectors, make them longer and change the pivot point
#(point around which they're rotated) to be the middle
# (point around which they're rotated) to be the middle
ax = plt.subplot(2, 2, 2)
ax.barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle')

# Showing colormapping with uniform grid. Fill the circle for an empty barb,
# don't round the values, and change some of the size parameters
ax = plt.subplot(2, 2, 3)
ax.barbs(X, Y, U, V, np.sqrt(U*U + V*V), fill_empty=True, rounding=False,
ax.barbs(X, Y, U, V, np.sqrt(U * U + V * V), fill_empty=True, rounding=False,
sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3))

# Change colors as well as the increments for parts of the barbs
ax = plt.subplot(2, 2, 4)
ax.barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r',
barbcolor=['b', 'g'], barb_increments=dict(half=10, full=20, flag=100),
flip_barb=True)
barbcolor=['b', 'g'],
barb_increments=dict(half=10, full=20, flag=100), flip_barb=True)

# Masked arrays are also supported
masked_u = np.ma.masked_array(data['u'])
masked_u[4] = 1000 # Bad value that should not be plotted when masked
masked_u[4] = np.ma.masked

# Identical plot to panel 2 in the first figure, but with the point at
#(0.5, 0.25) missing (masked)
# (0.5, 0.25) missing (masked)
fig2 = plt.figure()
ax = fig2.add_subplot(1, 1, 1)
ax.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle')
Expand Down
0