matplotlib手册(转载)

Plotting commands summary

matplotlib.pyplot. plotting ( )
FunctionDescription
acorrPlot the autocorrelation of x.
angle_spectrumPlot the angle spectrum.
annotateAnnotate the point xy with text s.
arrowAdd an arrow to the axes.
autoscaleAutoscale the axis view to the data (toggle).
axesAdd an axes to the figure.
axhlineAdd a horizontal line across the axis.
axhspanAdd a horizontal span (rectangle) across the axis.
axisConvenience method to get or set axis properties.
axvlineAdd a vertical line across the axes.
axvspanAdd a vertical span (rectangle) across the axes.
barMake a bar plot.
barbsPlot a 2-D field of barbs.
barhMake a horizontal bar plot.
boxTurn the axes box on or off.
boxplotMake a box and whisker plot.
broken_barhPlot horizontal bars.
claClear the current axes.
clabelLabel a contour plot.
clfClear the current figure.
climSet the color limits of the current image.
closeClose a figure window.
coherePlot the coherence between x and y.
colorbarAdd a colorbar to a plot.
contourPlot contours.
contourfPlot contours.
csdPlot the cross-spectral density.
delaxesRemove an axes from the current figure.
drawRedraw the current figure.
errorbarPlot an errorbar graph.
eventplotPlot identical parallel lines at specific positions.
figimageAdds a non-resampled image to the figure.
figlegendPlace a legend in the figure.
fignum_exists 
figtextAdd text to figure.
figureCreates a new figure.
fillPlot filled polygons.
fill_betweenMake filled polygons between two curves.
fill_betweenxMake filled polygons between two horizontal curves.
findobjFind artist objects.
gcaGet the current Axes instance on the current figure matching the given keyword args, or create one.
gcfGet a reference to the current figure.
gciGet the current colorable artist.
get_figlabelsReturn a list of existing figure labels.
get_fignumsReturn a list of existing figure numbers.
gridTurn the axes grids on or off.
hexbinMake a hexagonal binning plot.
histPlot a histogram.
hist2dMake a 2D histogram plot.
hlinesPlot horizontal lines at each y from xmin to xmax.
hold 
imreadRead an image from a file into an array.
imsaveSave an array as in image file.
imshowDisplay an image on the axes.
install_repl_displayhookInstall a repl display hook so that any stale figure are automatically redrawn when control is returned to the repl.
ioffTurn interactive mode off.
ionTurn interactive mode on.
ishold 
isinteractiveReturn status of interactive mode.
legendPlaces a legend on the axes.
locator_paramsControl behavior of tick locators.
loglogMake a plot with log scaling on both the x and y axis.
magnitude_spectrumPlot the magnitude spectrum.
marginsSet or retrieve autoscaling margins.
matshowDisplay an array as a matrix in a new figure window.
minorticks_offRemove minor ticks from the current plot.
minorticks_onDisplay minor ticks on the current plot.
over 
pausePause for interval seconds.
pcolorCreate a pseudocolor plot of a 2-D array.
pcolormeshPlot a quadrilateral mesh.
phase_spectrumPlot the phase spectrum.
piePlot a pie chart.
plotPlot lines and/or markers to the Axes.
plot_dateA plot with data that contains dates.
plotfilePlot the data in in a file.
polarMake a polar plot.
psdPlot the power spectral density.
quiverPlot a 2-D field of arrows.
quiverkeyAdd a key to a quiver plot.
rcSet the current rc params.
rc_contextReturn a context manager for managing rc settings.
rcdefaultsRestore the rc params from Matplotlib’s internal defaults.
rgridsGet or set the radial gridlines on a polar plot.
savefigSave the current figure.
scaSet the current Axes instance to ax.
scatterMake a scatter plot of x vs y Marker size is scaled by s and marker color is mapped to c Parameters ———- x, y : array_like, shape (n, ) Input data s : scalar or array_like, shape (n, ), optional size in points^2.
sciSet the current image.
semilogxMake a plot with log scaling on the x axis.
semilogyMake a plot with log scaling on the y axis.
set_cmapSet the default colormap.
setpSet a property on an artist object.
showDisplay a figure.
specgramPlot a spectrogram.
spyPlot the sparsity pattern on a 2-D array.
stackplotDraws a stacked area plot.
stemCreate a stem plot.
stepMake a step plot.
streamplotDraws streamlines of a vector flow.
subplotReturn a subplot axes positioned by the given grid definition.
subplot2gridCreate a subplot in a grid.
subplot_toolLaunch a subplot tool window for a figure.
subplotsCreate a figure and a set of subplots This utility wrapper makes it convenient to create common layouts of subplots, including the enclosing figure object, in a single call.
subplots_adjustTune the subplot layout.
suptitleAdd a centered title to the figure.
switch_backendSwitch the default backend.
tableAdd a table to the current axes.
textAdd text to the axes.
thetagridsGet or set the theta locations of the gridlines in a polar plot.
tick_paramsChange the appearance of ticks and tick labels.
ticklabel_formatChange the ScalarFormatter used by default for linear axes.
tight_layoutAutomatically adjust subplot parameters to give specified padding.
titleSet a title of the current axes.
tricontourDraw contours on an unstructured triangular grid.
tricontourfDraw contours on an unstructured triangular grid.
tripcolorCreate a pseudocolor plot of an unstructured triangular grid.
triplotDraw a unstructured triangular grid as lines and/or markers.
twinxMake a second axes that shares the x-axis.
twinyMake a second axes that shares the y-axis.
uninstall_repl_displayhookUninstalls the matplotlib display hook.
violinplotMake a violin plot.
vlinesPlot vertical lines.
xcorrPlot the cross correlation between x and y.
xkcdTurns on xkcd sketch-style drawing mode.
xlabelSet the x axis label of the current axis.
xlimGet or set the x limits of the current axes.
xscaleSet the scaling of the x-axis.
xticksGet or set the x-limits of the current tick locations and labels.
ylabelSet the y axis label of the current axis.
ylimGet or set the y-limits of the current axes.
yscaleSet the scaling of the y-axis.
yticksGet or set the y-limits of the current tick locations and labels.
matplotlib.pyplot. colormaps ( )

Matplotlib provides a number of colormaps, and others can be added usingregister_cmap(). This function documents the built-incolormaps, and will also return a list of all registered colormaps if called.

You can set the colormap for an image, pcolor, scatter, etc,using a keyword argument:

imshow(X, cmap=cm.hot)

or using the set_cmap() function:

imshow(X)
pyplot.set_cmap('hot')
pyplot.set_cmap('jet')

In interactive mode, set_cmap() will update the colormap post-hoc,allowing you to see which one works best for your data.

All built-in colormaps can be reversed by appending _r: For instance,gray_r is the reverse of gray.

There are several common color schemes used in visualization:

Sequential schemes
for unipolar data that progresses from low to high
Diverging schemes
for bipolar data that emphasizes positive or negative deviations from acentral value
Cyclic schemes
meant for plotting values that wrap around at theendpoints, such as phase angle, wind direction, or time of day
Qualitative schemes
for nominal data that has no inherent ordering, where color is usedonly to distinguish categories

The base colormaps are derived from those of the same name providedwith Matlab:

ColormapDescription
autumnsequential linearly-increasing shades of red-orange-yellow
bonesequential increasing black-white color map witha tinge of blue, to emulate X-ray film
coollinearly-decreasing shades of cyan-magenta
coppersequential increasing shades of black-copper
flagrepetitive red-white-blue-black pattern (not cyclic atendpoints)
graysequential linearly-increasing black-to-whitegrayscale
hotsequential black-red-yellow-white, to emulate blackbodyradiation from an object at increasing temperatures
hsvcyclic red-yellow-green-cyan-blue-magenta-red, formedby changing the hue component in the HSV color space
infernoperceptually uniform shades of black-red-yellow
jeta spectral map with dark endpoints, blue-cyan-yellow-red;based on a fluid-jet simulation by NCSA [1]
magmaperceptually uniform shades of black-red-white
pinksequential increasing pastel black-pink-white, meantfor sepia tone colorization of photographs
plasmaperceptually uniform shades of blue-red-yellow
prismrepetitive red-yellow-green-blue-purple-...-green pattern(not cyclic at endpoints)
springlinearly-increasing shades of magenta-yellow
summersequential linearly-increasing shades of green-yellow
viridisperceptually uniform shades of blue-green-yellow
winterlinearly-increasing shades of blue-green

For the above list only, you can also set the colormap using thecorresponding pylab shortcut interface function, similar to Matlab:

imshow(X)
hot()
jet()

The next set of palettes are from the Yorick scientific visualisationpackage, an evolution ofthe GIST package, both by David H. Munro:

ColormapDescription
gist_earthmapmaker’s colors from dark blue deep ocean to greenlowlands to brown highlands to white mountains
gist_heatsequential increasing black-red-orange-white, to emulateblackbody radiation from an iron bar as it grows hotter
gist_ncarpseudo-spectral black-blue-green-yellow-red-purple-whitecolormap from National Center for AtmosphericResearch [2]
gist_rainbowruns through the colors in spectral order from red toviolet at full saturation (like hsv but not cyclic)
gist_stern“Stern special” color table from Interactive DataLanguage software

The following colormaps are based on the ColorBrewer color specifications and designs developed byCynthia Brewer:

ColorBrewer Diverging (luminance is highest at the midpoint, anddecreases towards differently-colored endpoints):

ColormapDescription
BrBGbrown, white, blue-green
PiYGpink, white, yellow-green
PRGnpurple, white, green
PuOrorange, white, purple
RdBured, white, blue
RdGyred, white, gray
RdYlBured, yellow, blue
RdYlGnred, yellow, green
Spectralred, orange, yellow, green, blue

ColorBrewer Sequential (luminance decreases monotonically):

ColormapDescription
Blueswhite to dark blue
BuGnwhite, light blue, dark green
BuPuwhite, light blue, dark purple
GnBuwhite, light green, dark blue
Greenswhite to dark green
Greyswhite to black (not linear)
Orangeswhite, orange, dark brown
OrRdwhite, orange, dark red
PuBuwhite, light purple, dark blue
PuBuGnwhite, light purple, dark green
PuRdwhite, light purple, dark red
Purpleswhite to dark purple
RdPuwhite, pink, dark purple
Redswhite to dark red
YlGnlight yellow, dark green
YlGnBulight yellow, light green, dark blue
YlOrBrlight yellow, orange, dark brown
YlOrRdlight yellow, orange, dark red

ColorBrewer Qualitative:

(For plotting nominal data, ListedColormap is used,not LinearSegmentedColormap. Different sets of colors arerecommended for different numbers of categories.)

  • Accent
  • Dark2
  • Paired
  • Pastel1
  • Pastel2
  • Set1
  • Set2
  • Set3

Other miscellaneous schemes:

ColormapDescription
afmhotsequential black-orange-yellow-white blackbodyspectrum, commonly used in atomic force microscopy
brgblue-red-green
bwrdiverging blue-white-red
coolwarmdiverging blue-gray-red, meant to avoid issues with 3Dshading, color blindness, and ordering of colors [3]
CMRmap“Default colormaps on color images often reproduce toconfusing grayscale images. The proposed colormapmaintains an aesthetically pleasing color image thatautomatically reproduces to a monotonic grayscale withdiscrete, quantifiable saturation levels.” [4]
cubehelixUnlike most other color schemes cubehelix was designedby D.A. Green to be monotonically increasing in termsof perceived brightness. Also, when printed on a blackand white postscript printer, the scheme results in agreyscale with monotonically increasing brightness.This color scheme is named cubehelix because the r,g,bvalues produced can be visualised as a squashed helixaround the diagonal in the r,g,b color cube.
gnuplotgnuplot’s traditional pm3d scheme(black-blue-red-yellow)
gnuplot2sequential color printable as gray(black-blue-violet-yellow-white)
oceangreen-blue-white
rainbowspectral purple-blue-green-yellow-orange-red colormapwith diverging luminance
seismicdiverging blue-white-red
nipy_spectralblack-purple-blue-green-yellow-red-white spectrum,originally from the Neuroimaging in Python project
terrainmapmaker’s colors, blue-green-yellow-brown-white,originally from IGOR Pro

The following colormaps are redundant and may be removed in futureversions. It’s recommended to use the names in the descriptionsinstead, which produce identical output:

ColormapDescription
gist_grayidentical to gray
gist_yargidentical to gray_r
binaryidentical to gray_r
spectralidentical to nipy_spectral [5]

Footnotes

[1]Rainbow colormaps, jet in particular, are considered a poorchoice for scientific visualization by many researchers: Rainbow ColorMap (Still) Considered Harmful
[2]Resembles “BkBlAqGrYeOrReViWh200” from NCAR CommandLanguage. See Color Table Gallery
[3]See Diverging Color Maps for Scientific Visualization by Kenneth Moreland.
[4]See A Color Map for Effective Black-and-White Rendering ofColor-Scale Imagesby Carey Rappaport
[5]Changed to distinguish from ColorBrewer’s Spectral map.spectral() still works, butset_cmap('nipy_spectral') is recommended for clarity.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值