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

Skip to content

MEP12 pylab changes on zorder_demo.py #4630

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
Jul 11, 2015
Merged
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
43 changes: 25 additions & 18 deletions examples/pylab_examples/zorder_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,33 @@
The second figure shows how to control the zorder of individual lines.
"""

from pylab import *
x = rand(20)
y = rand(20)
import matplotlib.pyplot as plt
import numpy as np

subplot(211)
plot(x, y, 'r', lw=3)
scatter(x, y, s=120)
x = np.random.random(20)
y = np.random.random(20)

subplot(212)
plot(x, y, 'r', zorder=1, lw=3)
scatter(x, y, s=120, zorder=2)
# Lines on top of scatter
plt.figure()
plt.subplot(211)
plt.plot(x, y, 'r', lw=3)
plt.scatter(x, y, s=120)
plt.title('Lines on top of dots')

# Scatter plot on top of lines
plt.subplot(212)
plt.plot(x, y, 'r', zorder=1, lw=3)
plt.scatter(x, y, s=120, zorder=2)
plt.title('Dots on top of lines')

# A new figure, with individually ordered items
x = frange(0, 2*pi, npts=100)
figure()
plot(x, sin(x), linewidth=10, color='black', label='zorder=10', zorder=10) # on top
plot(x, cos(1.3*x), linewidth=10, color='red', label='zorder=1', zorder=1) # bottom
plot(x, sin(2.1*x), linewidth=10, color='green', label='zorder=3', zorder=3)
axhline(0, linewidth=10, color='blue', label='zorder=2', zorder=2)
l = legend()
x = np.linspace(0, 2*np.pi, 100)
plt.figure()
plt.plot(x, np.sin(x), linewidth=10, color='black', label='zorder=10', zorder=10) # on top
plt.plot(x, np.cos(1.3*x), linewidth=10, color='red', label='zorder=1', zorder=1) # bottom
plt.plot(x, np.sin(2.1*x), linewidth=10, color='green', label='zorder=3', zorder=3)
plt.axhline(0, linewidth=10, color='blue', label='zorder=2', zorder=2)
plt.title('Custom order of elements')
l = plt.legend()
l.set_zorder(20) # put the legend on top

show()
plt.show()