8000 Merge pull request #921 from endolith/patch-6 · matplotlib/matplotlib@5970bde · GitHub
[go: up one dir, main page]

Skip to content

Commit 5970bde

Browse files
committed
Merge pull request #921 from endolith/patch-6
Change colormaps for examples
2 parents 2b4ab26 + 8b80779 commit 5970bde

Some content is hidden

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

50 files changed

+101
-81
lines changed

examples/mplot3d/contour3d_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from mpl_toolkits.mplot3d import axes3d
22
import matplotlib.pyplot as plt
3+
from matplotlib import cm
34

45
fig = plt.figure()
56
ax = fig.add_subplot(111, projection='3d')
67
X, Y, Z = axes3d.get_test_data(0.05)
7-
cset = ax.contour(X, Y, Z)
8+
cset = ax.contour(X, Y, Z, cmap=cm.coolwarm)
89
ax.clabel(cset, fontsize=9, inline=1)
910

1011
plt.show()

examples/mplot3d/contour3d_demo2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from mpl_toolkits.mplot3d import axes3d
22
import matplotlib.pyplot as plt
3+
from matplotlib import cm
34

45
fig = plt.figure()
56
ax = fig.gca(projection='3d')
67
X, Y, Z = axes3d.get_test_data(0.05)
7-
cset = ax.contour(X, Y, Z, extend3d=True)
8+
cset = ax.contour(X, Y, Z, extend3d=True, cmap=cm.coolwarm)
89
ax.clabel(cset, fontsize=9, inline=1)
910

1011
plt.show()

examples/mplot3d/contour3d_demo3.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from mpl_toolkits.mplot3d import axes3d
22
import matplotlib.pyplot as plt
3+
from matplotlib import cm
34

45
fig = plt.figure()
56
ax = fig.gca(projection='3d')
67
X, Y, Z = axes3d.get_test_data(0.05)
78
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
8-
cset = ax.contour(X, Y, Z, zdir='z', offset=-100)
9-
cset = ax.contour(X, Y, Z, zdir='x', offset=-40)
10-
cset = ax.contour(X, Y, Z, zdir='y', offset=40)
9+
cset = ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
10+
cset = ax.contour(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
11+
cset = ax.contour(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)
1112

1213
ax.set_xlabel('X')
1314
ax.set_xlim(-40, 40)

examples/mplot3d/contourf3d_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from mpl_toolkits.mplot3d import axes3d
22
import matplotlib.pyplot as plt
3+
from matplotlib import cm
34

45
fig = plt.figure()
56
ax = fig.gca(projection='3d')
67
X, Y, Z = axes3d.get_test_data(0.05)
7-
cset = ax.contourf(X, Y, Z)
8+
cset = ax.contourf(X, Y, Z, cmap=cm.coolwarm)
89
ax.clabel(cset, fontsize=9, inline=1)
910

1011
plt.show()

examples/mplot3d/contourf3d_demo2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
from mpl_toolkits.mplot3d import axes3d
77
import matplotlib.pyplot as plt
8+
from matplotlib import cm
89

910
fig = plt.figure()
1011
ax = fig.gca(projection='3d')
1112
X, Y, Z = axes3d.get_test_data(0.05)
1213
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
13-
cset = ax.contourf(X, Y, Z, zdir='z', offset=-100)
14-
cset = ax.contourf(X, Y, Z, zdir='x', offset=-40)
15-
cset = ax.contourf(X, Y, Z, zdir='y', offset=40)
14+
cset = ax.contourf(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
15+
cset = ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
16+
cset = ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)
1617

1718
ax.set_xlabel('X')
1819
ax.set_xlim(-40, 40)

examples/mplot3d/subplot3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
X, Y = np.meshgrid(X, Y)
1818
R = np.sqrt(X**2 + Y**2)
1919
Z = np.sin(R)
20-
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,
20+
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
2121
linewidth=0, antialiased=False)
2222
ax.set_zlim3d(-1.01, 1.01)
2323

examples/mplot3d/surface3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
X, Y = np.meshgrid(X, Y)
1212
R = np.sqrt(X**2 + Y**2)
1313
Z = np.sin(R)
14-
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,
14+
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
1515
linewidth=0, antialiased=False)
1616
ax.set_zlim(-1.01, 1.01)
1717

examples/mplot3d/surface3d_radial_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
X,Y = R*np.cos(P),R*np.sin(P)
1919

2020
Z = ((R**2 - 1)**2)
21-
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet)
21+
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.YlGnBu_r)
2222
ax.set_zlim3d(0, 1)
2323
ax.set_xlabel(r'$\phi_\mathrm{real}$')
2424
ax.set_ylabel(r'$\phi_\mathrm{im}$')

examples/pylab_examples/agg_buffer_to_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
ax.set_title('a simple figure')
1010
fig.canvas.draw()
1111

12-
# grab rhe pixel buffer and dumpy it into a numpy array
12+
# grab the pixel buffer and dump it into a numpy array
1313
buf = fig.canvas.buffer_rgba()
1414
l, b, w, h = fig.bbox.bounds
1515
X = np.frombuffer(buf, np.uint8)

examples/pylab_examples/anchored_artists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, transform, size, label, loc,
2222
pad=0.1, borderpad=0.1, sep=2, prop=None, frameon=True):
2323
"""
2424
Draw a horizontal bar with the size in data coordinate of the give axes.
25-
A label will be drawn underneath (center-alinged).
25+
A label will be drawn underneath (center-aligned).
2626
2727
pad, borderpad in fraction of the legend font size (or prop)
2828
sep in points.

examples/pylab_examples/annotation_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113

114114

115115
if 1:
116-
# You can also use polar notation on a catesian axes. Here the
116+
# You can also use polar notation on a cartesian axes. Here the
117117
# native coordinate system ('data') is cartesian, so you need to
118118
# specify the xycoords and textcoords as 'polar' if you want to
119119
# use (theta, radius)

examples/pylab_examples/axhspan_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# draw a default vline at x=1 that spans the yrange
1515
l = plt.axvline(x=1)
1616

17-
# draw a thick blue vline at x=0 that spans the the upper quadrant of
17+
# draw a thick blue vline at x=0 that spans the upper quadrant of
1818
# the yrange
1919
l = plt.axvline(x=0, ymin=0.75, linewidth=4, color='b')
2020

examples/pylab_examples/boxplot_demo2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
medianY.append(med.get_ydata()[j])
8181
plt.plot(medianX, medianY, 'k')
8282
medians[i] = medianY[0]
83-
# Finally, overplot the sample averages, with horixzontal alignment
83+
# Finally, overplot the sample averages, with horizontal alignment
8484
# in the center of each box
8585
plt.plot([np.average(med.get_xdata())], [np.average(data[i])],
8686
color='w', marker='*', markeredgecolor='k')

examples/pylab_examples/centered_ticklabels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# sometimes it is nice to have ticklabels centered. mpl currently
22
# associates a label with a tick, and the label can be aligned
3-
# 'center', 'feft', or 'right' using the horizontal alignment property:
3+
# 'center', 'left', or 'right' using the horizontal alignment property:
44
#
55
#
66
# for label in ax.xaxis.get_xticklabels():
7-
# label.set_horizntal_alignment('right')
7+
# label.set_horizontalalignment('right')
88
#
99
#
1010
# but this doesn't help center the label between ticks. One solution

examples/pylab_examples/colorbar_tick_labelling_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import matplotlib.pyplot as plt
77
import numpy as np
8-
8+
from matplotlib import cm
99
from numpy.random import randn
1010

1111
# Make plot with vertical (default) colorbar
@@ -14,7 +14,7 @@
1414

1515
data = np.clip(randn(250, 250), -1, 1)
1616

17-
cax = ax.imshow(data, interpolation='nearest')
17+
cax = ax.imshow(data, interpolation='nearest', cmap=cm.coolwarm)
1818
ax.set_title('Gaussian noise with vertical colorbar')
1919

2020
# Add colorbar, make sure to specify tick locations to match desired ticklabels
@@ -27,7 +27,7 @@
2727

2828
data = np.clip(randn(250, 250), -1, 1)
2929

30-
cax = ax.imshow(data, interpolation='nearest')
30+
cax = ax.imshow(data, interpolation='nearest', cmap=cm.afmhot)
3131
ax.set_title('Gaussian noise with horizontal colorbar')
3232

3333
cbar = fig.colorbar(cax, ticks=[-1, 0, 1], orientation='horizontal')

examples/pylab_examples/contour_image.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@
2626
levels = arange(-2.0, 1.601, 0.4) # Boost the upper limit to avoid truncation
2727
# errors.
2828

29+
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
30+
cmap = cm.PRGn
31+
2932
figure()
3033

3134

3235
subplot(2,2,1)
3336

3437
cset1 = contourf(X, Y, Z, levels,
35-
cmap=cm.get_cmap('jet', len(levels)-1),
38+
cmap=cm.get_cmap(cmap, len(levels)-1),
39+
norm=norm,
3640
)
3741
# It is not necessary, but for the colormap, we need only the
3842
# number of levels minus 1. To avoid discretization error, use
@@ -65,7 +69,7 @@
6569

6670
subplot(2,2,2)
6771

68-
imshow(Z, extent=extent)
72+
imshow(Z, extent=extent, cmap=cmap, norm=norm)
6973
v = axis()
7074
contour(Z, levels, hold='on', colors = 'k',
7175
origin='upper', extent=extent)
@@ -74,7 +78,7 @@
7478

7579
subplot(2,2,3)
7680

77-
imshow(Z, origin='lower', extent=extent)
81+
imshow(Z, origin='lower', extent=extent, cmap=cmap, norm=norm)
7882
v = axis()
7983
contour(Z, levels, hold='on', colors = 'k',
8084
origin='lower', extent=extent)
@@ -89,7 +93,7 @@
8993
# This is intentional. The Z values are defined at the center of each
9094
# image pixel (each color block on the following subplot), so the
9195
# domain that is contoured does not extend beyond these pixel centers.
92-
im = imshow(Z, interpolation='nearest', extent=extent)
96+
im = imshow(Z, interpolation='nearest', extent=extent, cmap=cmap, norm=norm)
9397
v = axis()
9498
contour(Z, levels, hold='on', colors = 'k',
9599
origin='image', extent=extent)

examples/pylab_examples/contourf_log.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from matplotlib import pyplot as P
66
import numpy as np
77
from numpy import ma
8-
from matplotlib import colors, ticker
8+
from matplotlib import colors, ticker, cm
99
from matplotlib.mlab import bivariate_normal
1010

1111
N = 100
@@ -30,7 +30,7 @@
3030

3131
# Automatic selection of levels works; setting the
3232
# log locator tells contourf to use a log scale:
33-
cs = P.contourf(X, Y, z, locator=ticker.LogLocator())
33+
341A cs = P.contourf(X, Y, z, locator=ticker.LogLocator(), cmap=cm.PuBu_r)
3434

3535
# Alternatively, you can manually set the levels
3636
# and the norm:

examples/pylab_examples/custom_figure_class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
You can pass a custom Figure constructor to figure if youy want to derive from the default Figure. This simple example creates a figure with a figure title
2+
You can pass a custom Figure constructor to figure if you want to derive from the default Figure. This simple example creates a figure with a figure title
33
"""
44
from matplotlib.pyplot import figure, show
55
from matplotlib.figure import Figure

examples/pylab_examples/custom_ticker1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
"""
4-
The new ticker code was designed to explicity support user customized
4+
The new ticker code was designed to explicitly support user customized
55
ticking. The documentation
66
http://matplotlib.sourceforge.net/matplotlib.ticker.html details this
77
process. That code defines a lot of preset tickers but was primarily

examples/pylab_examples/customize_rc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
"""
3-
I'm not trying to make a good liking figure here, but just to show
3+
I'm not trying to make a good looking figure here, but just to show
44
some examples of customizing rc params on the fly
55
66
If you like to work interactively, and need to create different sets
@@ -36,7 +36,7 @@ def set_pub():
3636
rc('xtick.major', size=5, pad=7)
3737
rc('xtick', labelsize=15)
3838

39-
# using aliases for color, linestyle and linewith; gray, solid, thick
39+
# using aliases for color, linestyle and linewidth; gray, solid, thick
4040
rc('grid', c='0.5', ls='-', lw=5)
4141
rc('lines', lw=2, color='g')
4242
subplot(312)

examples/pylab_examples/date_demo_convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
ax.plot_date(dates, y*y)
1818

1919
# this is superfluous, since the autoscaler should get it right, but
20-
# use date2num and num2date to to convert between dates and floats if
20+
# use date2num and num2date to convert between dates and floats if
2121
# you want; both date2num and num2date convert an instance or sequence
2222
ax.set_xlim( dates[0], dates[-1] )
2323

examples/pylab_examples/demo_agg_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def filtered_text(ax):
221221

222222

223223
def drop_shadow_line(ax):
224-
# copyed from examples/misc/svg_filter_line.py
224+
# copied from examples/misc/svg_filter_line.py
225225

226226
# draw lines
227227
l1, = ax.plot([0.1, 0.5, 0.9], [0.1, 0.9, 0.5], "bo-",

examples/pylab_examples/fancybox_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test1(ax):
4242
def test2(ax):
4343

4444
# bbox=round has two optional argument. pad and rounding_size.
45-
# They can be set during the initiallization.
45+
# They can be set during the initialization.
4646
p_fancy = FancyBboxPatch((bb.xmin, bb.ymin),
4747
abs(bb.width), abs(bb.height),
4848
boxstyle="round,pad=0.1",

examples/pylab_examples/finance_work2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95 10000 ,7 +95,7 @@ def moving_average_convergence(x, nslow=26, nfast=12):
9595

9696

9797
fig = plt.figure(facecolor='white')
98-
axescolor = '#f6f6f6' # the axies background color
98+
axescolor = '#f6f6f6' # the axes background color
9999

100100
ax1 = fig.add_axes(rect1, axisbg=axescolor) #left, bottom, width, height
101101
ax2 = fig.add_axes(rect2, axisbg=axescolor, sharex=ax1)

examples/pylab_examples/ganged_plots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
"""
33
To create plots that share a common axes (visually) you can set the
4-
hspace bewtween the subplots close to zero (do not use zero itself).
4+
hspace between the subplots close to zero (do not use zero itself).
55
Normally you'll want to turn off the tick labels on all but one of the
66
axes.
77

examples/pylab_examples/griddata_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
zi = griddata(x,y,z,xi,yi,interp='linear')
1717
# contour the gridded data, plotting dots at the nonuniform data points.
1818
CS = plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k')
19-
CS = plt.contourf(xi,yi,zi,15,cmap=plt.cm.jet)
19+
CS = plt.contourf(xi,yi,zi,15,cmap=plt.cm.rainbow,
20+
vmax=abs(zi).max(), vmin=-abs(zi).max())
2021
plt.colorbar() # draw colorbar
2122
# plot data points.
2223
plt.scatter(x,y,marker='o',c='b',s=5,zorder=10)

examples/pylab_examples/hexbin_demo.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"""
77

88
import numpy as np
9-
import matplotlib.cm as cm
10-
import matplotlib.pyplot as plt
9+
import matplotlib.pyplot as plt
1110

1211
np.random.seed(0)
1312
n = 100000
@@ -20,14 +19,14 @@
2019

2120
plt.subplots_adjust(hspace=0.5)
2221
plt.subplot(121)
23-
plt.hexbin(x,y, cmap=cm.jet)
22+
plt.hexbin(x,y, cmap=plt.cm.YlOrRd_r)
2423
plt.axis([xmin, xmax, ymin, ymax])
2524
plt.title("Hexagon binning")
2625
cb = plt.colorbar()
2726
cb.set_label('counts')
2827

2928
plt.subplot(122)
30-
plt.hexbin(x,y,bins='log', cmap=cm.jet)
29+
plt.hexbin(x,y,bins='log', cmap=plt.cm.YlOrRd_r)
3130
plt.axis([xmin, xmax, ymin, ymax])
3231
plt.title("With a log color scale")
3332
cb = plt.colorbar()

examples/pylab_examples/hexbin_demo2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@
3939
gridsize=30
4040

4141
plt.subplot(211)
42-
plt.hexbin(x,y, C=z, gridsize=gridsize, marginals=True)
42+
plt.hexbin(x,y, C=z, gridsize=gridsize, marginals=True, cmap=plt.cm.RdBu,
43+
vmax=abs(z).max(), vmin=-abs(z).max())
4344
plt.axis([xmin, xmax, ymin, ymax])
4445
cb = plt.colorbar()
4546
cb.set_label('mean value')
4647

4748

4849
plt.subplot(212)
49-
plt.hexbin(x,y, gridsize=gridsize)
50+
plt.hexbin(x,y, gridsize=gridsize, cmap=plt.cm.Blues_r)
5051
plt.axis([xmin, xmax, ymin, ymax])
5152
cb = plt.colorbar()
5253
cb.set_label('N observations')

examples/pylab_examples/image_demo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
1212
Z = Z2-Z1 # difference of Gaussians
1313

14-
im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray,
15-
origin='lower', extent=[-3,3,-3,3])
14+
im = plt.imshow(Z, interpolation='bilinear', cmap=cm.RdYlGn,
15+
origin='lower', extent=[-3,3,-3,3],
16+
vmax=abs(Z).max(), vmin=-abs(Z).max())
1617

1718
plt.show()
1819

0 commit comments

Comments
 (0)
0