Skip to content

DOC: Change colormaps for examples (showcase different types, discourage 'jet') #921

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 19 commits into from
Jun 24, 2012
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
3 changes: 2 additions & 1 deletion examples/mplot3d/contour3d_demo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
cset = ax.contour(X, Y, Z)
cset = ax.contour(X, Y, Z, cmap=cm.coolwarm)
ax.clabel(cset, fontsize=9, inline=1)

plt.show()
Expand Down
3 changes: 2 additions & 1 deletion examples/mplot3d/contour3d_demo2.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
cset = ax.contour(X, Y, Z, extend3d=True)
cset = ax.contour(X, Y, Z, extend3d=True, cmap=cm.coolwarm)
ax.clabel(cset, fontsize=9, inline=1)

plt.show()
Expand Down
7 changes: 4 additions & 3 deletions examples/mplot3d/contour3d_demo3.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

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

ax.set_xlabel('X')
ax.set_xlim(-40, 40)
Expand Down
3 changes: 2 additions & 1 deletion examples/mplot3d/contourf3d_demo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
cset = ax.contourf(X, Y, Z)
cset = ax.contourf(X, Y, Z, cmap=cm.coolwarm)
ax.clabel(cset, fontsize=9, inline=1)

plt.show()
Expand Down
7 changes: 4 additions & 3 deletions examples/mplot3d/contourf3d_demo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
cset = ax.contourf(X, Y, Z, zdir='z', offset=-100)
cset = ax.contourf(X, Y, Z, zdir='x', offset=-40)
cset = ax.contourf(X, Y, Z, zdir='y', offset=40)
cset = ax.contourf(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)

ax.set_xlabel('X')
ax.set_xlim(-40, 40)
Expand Down
2 changes: 1 addition & 1 deletion examples/mplot3d/subplot3d_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim3d(-1.01, 1.01)

Expand Down
2 changes: 1 addition & 1 deletion examples/mplot3d/surface3d_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)

Expand Down
2 changes: 1 addition & 1 deletion examples/mplot3d/surface3d_radial_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
X,Y = R*np.cos(P),R*np.sin(P)

Z = ((R**2 - 1)**2)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.YlGnBu_r)
ax.set_zlim3d(0, 1)
ax.set_xlabel(r'$\phi_\mathrm{real}$')
ax.set_ylabel(r'$\phi_\mathrm{im}$')
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/agg_buffer_to_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ax.set_title('a simple figure')
fig.canvas.draw()

# grab rhe pixel buffer and dumpy it into a numpy array
# grab the pixel buffer and dump it into a numpy array
buf = fig.canvas.buffer_rgba()
l, b, w, h = fig.bbox.bounds
X = np.frombuffer(buf, np.uint8)
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/anchored_artists.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, transform, size, label, loc,
pad=0.1, borderpad=0.1, sep=2, prop=None, frameon=True):
"""
Draw a horizontal bar with the size in data coordinate of the give axes.
A label will be drawn underneath (center-alinged).
A label will be drawn underneath (center-aligned).

pad, borderpad in fraction of the legend font size (or prop)
sep in points.
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/annotation_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@


if 1:
# You can also use polar notation on a catesian axes. Here the
# You can also use polar notation on a cartesian axes. Here the
# native coordinate system ('data') is cartesian, so you need to
# specify the xycoords and textcoords as 'polar' if you want to
# use (theta, radius)
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/axhspan_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# draw a default vline at x=1 that spans the yrange
l = plt.axvline(x=1)

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

Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/boxplot_demo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
medianY.append(med.get_ydata()[j])
plt.plot(medianX, medianY, 'k')
medians[i] = medianY[0]
# Finally, overplot the sample averages, with horixzontal alignment
# Finally, overplot the sample averages, with horizontal alignment
# in the center of each box
plt.plot([np.average(med.get_xdata())], [np.average(data[i])],
color='w', marker='*', markeredgecolor='k')
Expand Down
4 changes: 2 additions & 2 deletions examples/pylab_examples/centered_ticklabels.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# sometimes it is nice to have ticklabels centered. mpl currently
# associates a label with a tick, and the label can be aligned
# 'center', 'feft', or 'right' using the horizontal alignment property:
# 'center', 'left', or 'right' using the horizontal alignment property:
#
#
# for label in ax.xaxis.get_xticklabels():
# label.set_horizntal_alignment('right')
# label.set_horizontalalignment('right')
#
#
# but this doesn't help center the label between ticks. One solution
Expand Down
6 changes: 3 additions & 3 deletions examples/pylab_examples/colorbar_tick_labelling_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import matplotlib.pyplot as plt
import numpy as np

from matplotlib import cm
from numpy.random import randn

# Make plot with vertical (default) colorbar
Expand All @@ -14,7 +14,7 @@

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

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

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

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

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

cbar = fig.colorbar(cax, ticks=[-1, 0, 1], orientation='horizontal')
Expand Down
12 changes: 8 additions & 4 deletions examples/pylab_examples/contour_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
levels = arange(-2.0, 1.601, 0.4) # Boost the upper limit to avoid truncation
# errors.

norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
cmap = cm.PRGn

figure()


subplot(2,2,1)

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

subplot(2,2,2)

imshow(Z, extent=extent)
imshow(Z, extent=extent, cmap=cmap, norm=norm)
v = axis()
contour(Z, levels, hold='on', colors = 'k',
origin='upper', extent=extent)
Expand All @@ -74,7 +78,7 @@

subplot(2,2,3)

imshow(Z, origin='lower', extent=extent)
imshow(Z, origin='lower', extent=extent, cmap=cmap, norm=norm)
v = axis()
contour(Z, levels, hold='on', colors = 'k',
origin='lower', extent=extent)
Expand All @@ -89,7 +93,7 @@
# This is intentional. The Z values are defined at the center of each
# image pixel (each color block on the following subplot), so the
# domain that is contoured does not extend beyond these pixel centers.
im = imshow(Z, interpolation='nearest', extent=extent)
im = imshow(Z, interpolation='nearest', extent=extent, cmap=cmap, norm=norm)
v = axis()
contour(Z, levels, hold='on', colors = 'k',
origin='image', extent=extent)
Expand Down
4 changes: 2 additions & 2 deletions examples/pylab_examples/contourf_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from matplotlib import pyplot as P
import numpy as np
from numpy import ma
from matplotlib import colors, ticker
from matplotlib import colors, ticker, cm
from matplotlib.mlab import bivariate_normal

N = 100
Expand All @@ -30,7 +30,7 @@

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

# Alternatively, you can manually set the levels
# and the norm:
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/custom_figure_class.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
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
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
"""
from matplotlib.pyplot import figure, show
from matplotlib.figure import Figure
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/custom_ticker1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

"""
The new ticker code was designed to explicity support user customized
The new ticker code was designed to explicitly support user customized
ticking. The documentation
http://matplotlib.sourceforge.net/matplotlib.ticker.html details this
process. That code defines a lot of preset tickers but was primarily
Expand Down
4 changes: 2 additions & 2 deletions examples/pylab_examples/customize_rc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

"""
I'm not trying to make a good liking figure here, but just to show
I'm not trying to make a good looking figure here, but just to show
some examples of customizing rc params on the fly

If you like to work interactively, and need to create different sets
Expand Down Expand Up @@ -36,7 +36,7 @@ def set_pub():
rc('xtick.major', size=5, pad=7)
rc('xtick', labelsize=15)

# using aliases for color, linestyle and linewith; gray, solid, thick
# using aliases for color, linestyle and linewidth; gray, solid, thick
rc('grid', c='0.5', ls='-', lw=5)
rc('lines', lw=2, color='g')
subplot(312)
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/date_demo_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ax.plot_date(dates, y*y)

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

Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/demo_agg_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def filtered_text(ax):


def drop_shadow_line(ax):
# copyed from examples/misc/svg_filter_line.py
# copied from examples/misc/svg_filter_line.py

# draw lines
l1, = ax.plot([0.1, 0.5, 0.9], [0.1, 0.9, 0.5], "bo-",
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/fancybox_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test1(ax):
def test2(ax):

# bbox=round has two optional argument. pad and rounding_size.
# They can be set during the initiallization.
# They can be set during the initialization.
p_fancy = FancyBboxPatch((bb.xmin, bb.ymin),
abs(bb.width), abs(bb.height),
boxstyle="round,pad=0.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/finance_work2.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def moving_average_convergence(x, nslow=26, nfast=12):


fig = plt.figure(facecolor='white')
axescolor = '#f6f6f6' # the axies background color
axescolor = '#f6f6f6' # the axes background color

ax1 = fig.add_axes(rect1, axisbg=axescolor) #left, bottom, width, height
ax2 = fig.add_axes(rect2, axisbg=axescolor, sharex=ax1)
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/ganged_plots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
"""
To create plots that share a common axes (visually) you can set the
hspace bewtween the subplots close to zero (do not use zero itself).
hspace between the subplots close to zero (do not use zero itself).
Normally you'll want to turn off the tick labels on all but one of the
axes.

Expand Down
3 changes: 2 additions & 1 deletion examples/pylab_examples/griddata_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
zi = griddata(x,y,z,xi,yi,interp='linear')
# contour the gridded data, plotting dots at the nonuniform data points.
CS = plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k')
CS = plt.contourf(xi,yi,zi,15,cmap=plt.cm.jet)
CS = plt.contourf(xi,yi,zi,15,cmap=plt.cm.rainbow,
vmax=abs(zi).max(), vmin=-abs(zi).max())
plt.colorbar() # draw colorbar
# plot data points.
plt.scatter(x,y,marker='o',c='b',s=5,zorder=10)
Expand Down
7 changes: 3 additions & 4 deletions examples/pylab_examples/hexbin_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"""

import numpy as np
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt

np.random.seed(0)
n = 100000
Expand All @@ -20,14 +19,14 @@

plt.subplots_adjust(hspace=0.5)
plt.subplot(121)
plt.hexbin(x,y, cmap=cm.jet)
plt.hexbin(x,y, cmap=plt.cm.YlOrRd_r)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("Hexagon binning")
cb = plt.colorbar()
cb.set_label('counts')

plt.subplot(122)
plt.hexbin(x,y,bins='log', cmap=cm.jet)
plt.hexbin(x,y,bins='log', cmap=plt.cm.YlOrRd_r)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("With a log color scale")
cb = plt.colorbar()
Expand Down
5 changes: 3 additions & 2 deletions examples/pylab_examples/hexbin_demo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@
gridsize=30

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


plt.subplot(212)
plt.hexbin(x,y, gridsize=gridsize)
plt.hexbin(x,y, gridsize=gridsize, cmap=plt.cm.Blues_r)
plt.axis([xmin, xmax, ymin, ymax])
cb = plt.colorbar()
cb.set_label('N observations')
Expand Down
5 changes: 3 additions & 2 deletions examples/pylab_examples/image_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = Z2-Z1 # difference of Gaussians

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

plt.show()

Loading