Matplotlib API解释说明
来源:互联网 发布:数据库培训中心 编辑:程序博客网 时间:2024/06/11 05:10
转载自:http://matplotlib.org/devdocs/api/pyplot_summary.html
Below we describe several common approaches to plotting with Matplotlib.
Contents
- The Pyplot API
- The Object-Oriented API
- Colors in Matplotlib
The Pyplot API
The matplotlib.pyplot
module contains functions that allow you to generate many kinds of plots quickly. For examples that showcase the use of the matplotlib.pyplot
module, see the Pyplot tutorial or the Pyplot Examples. We also recommend that you look into the object-oriented approach to plotting, described below.
matplotlib.pyplot.
plotting
()Function Description acorr
Plot the autocorrelation ofx
.angle_spectrum
Plot the angle spectrum.annotate
Annotate the pointxy
with texts
.arrow
Add an arrow to the axes.autoscale
Autoscale the axis view to the data (toggle).axes
Add an axes to the figure.axhline
Add a horizontal line across the axis.axhspan
Add a horizontal span (rectangle) across the axis.axis
Convenience method to get or set axis properties.axvline
Add a vertical line across the axes.axvspan
Add a vertical span (rectangle) across the axes.bar
Make a bar plot.barbs
Plot a 2-D field of barbs.barh
Make a horizontal bar plot.box
Turn the axes box on or off.boxplot
Make a box and whisker plot.broken_barh
Plot horizontal bars.cla
Clear the current axes.clabel
Label a contour plot.clf
Clear the current figure.clim
Set the color limits of the current image.close
Close a figure window.cohere
Plot the coherence between x and y.colorbar
Add a colorbar to a plot.contour
Plot contours.contourf
Plot contours.csd
Plot the cross-spectral density.delaxes
Remove an axes from the current figure.draw
Redraw the current figure.errorbar
Plot an errorbar graph.eventplot
Plot identical parallel lines at the given positions.figimage
Adds a non-resampled image to the figure.figlegend
Place a legend in the figure.fignum_exists
figtext
Add text to figure.figure
Creates a new figure.fill
Plot filled polygons.fill_between
Make filled polygons between two curves.fill_betweenx
Make filled polygons between two horizontal curves.findobj
Find artist objects.gca
Get the currentAxes
instance on the current figure matching the given keyword args, or create one.gcf
Get a reference to the current figure.gci
Get the current colorable artist.get_figlabels
Return a list of existing figure labels.get_fignums
Return a list of existing figure numbers.grid
Turn the axes grids on or off.hexbin
Make a hexagonal binning plot.hist
Plot a histogram.hist2d
Make a 2D histogram plot.hlines
Plot horizontal lines at eachy
fromxmin
toxmax
.hold
imread
Read an image from a file into an array.imsave
Save an array as in image file.imshow
Display an image on the axes.install_repl_displayhook
Install a repl display hook so that any stale figure are automatically redrawn when control is returned to the repl.ioff
Turn interactive mode off.ion
Turn interactive mode on.ishold
isinteractive
Return status of interactive mode.legend
Places a legend on the axes.locator_params
Control behavior of tick locators.loglog
Make a plot with log scaling on both the x and y axis.magnitude_spectrum
Plot the magnitude spectrum.margins
Set or retrieve autoscaling margins.matshow
Display an array as a matrix in a new figure window.minorticks_off
Remove minor ticks from the current plot.minorticks_on
Display minor ticks on the current plot.over
pause
Pause for interval seconds.pcolor
Create a pseudocolor plot of a 2-D array.pcolormesh
Plot a quadrilateral mesh.phase_spectrum
Plot the phase spectrum.pie
Plot a pie chart.plot
Plot lines and/or markers to theAxes
.plot_date
A plot with data that contains dates.plotfile
Plot the data in a file.polar
Make a polar plot.psd
Plot the power spectral density.quiver
Plot a 2-D field of arrows.quiverkey
Add a key to a quiver plot.rc
Set the current rc params.rc_context
Return a context manager for managing rc settings.rcdefaults
Restore the rc params from Matplotlib’s internal defaults.rgrids
Get or set the radial gridlines on a polar plot.savefig
Save the current figure.sca
Set the current Axes instance to ax.scatter
Make a scatter plot ofx
vsy
.sci
Set the current image.semilogx
Make a plot with log scaling on the x axis.semilogy
Make a plot with log scaling on they
axis.set_cmap
Set the default colormap.setp
Set a property on an artist object.show
Display a figure.specgram
Plot a spectrogram.spy
Plot the sparsity pattern on a 2-D array.stackplot
Draws a stacked area plot.stem
Create a stem plot.step
Make a step plot.streamplot
Draws streamlines of a vector flow.subplot
Return a subplot axes positioned by the given grid definition.subplot2grid
Create a subplot in a grid.subplot_tool
Launch a subplot tool window for a figure.subplots
Create 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_adjust
Tune the subplot layout.suptitle
Add a centered title to the figure.switch_backend
Switch the default backend.table
Add a table to the current axes.text
Add text to the axes.thetagrids
Get or set the theta locations of the gridlines in a polar plot.tick_params
Change the appearance of ticks and tick labels.ticklabel_format
Change theScalarFormatter
used by default for linear axes.tight_layout
Automatically adjust subplot parameters to give specified padding.title
Set a title of the current axes.tricontour
Draw contours on an unstructured triangular grid.tricontourf
Draw contours on an unstructured triangular grid.tripcolor
Create a pseudocolor plot of an unstructured triangular grid.triplot
Draw a unstructured triangular grid as lines and/or markers.twinx
Make a second axes that shares the x-axis.twiny
Make a second axes that shares the y-axis.uninstall_repl_displayhook
Uninstalls the matplotlib display hook.violinplot
Make a violin plot.vlines
Plot vertical lines.xcorr
Plot the cross correlation between x and y.xkcd
Turns on xkcd sketch-style drawing mode.xlabel
Set the x axis label of the current axis.xlim
Get or set the x limits of the current axes.xscale
Set the scaling of the x-axis.xticks
Get or set the x-limits of the current tick locations and labels.ylabel
Set the y axis label of the current axis.ylim
Get or set the y-limits of the current axes.yscale
Set the scaling of the y-axis.yticks
Get or set the y-limits of the current tick locations and labels.
The Object-Oriented API
Most of these functions also exist as methods in the matplotlib.axes.Axes
class. You can use them with the “Object Oriented” approach to Matplotlib.
While it is easy to quickly generate plots with the matplotlib.pyplot
module, we recommend using the object-oriented approach for more control and customization of your plots. See the methods in the matplotlib.axes.Axes()
class for many of the same plotting functions. For examples of the OO approach to Matplotlib, see the API Examples.
Colors in Matplotlib
There are many colormaps you can use to map data onto color values. Below we list several ways in which color can be utilized in Matplotlib.
For a more in-depth look at colormaps, see the Colormaps in Matplotlib tutorial.
matplotlib.pyplot.
colormaps
()Matplotlib provides a number of colormaps, and others can be added using
register_cmap()
. This function documents the built-in colormaps, 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 ofgray
.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 a central value
- Cyclic schemes
- meant for plotting values that wrap around at the endpoints, such as phase angle, wind direction, or time of day
- Qualitative schemes
- for nominal data that has no inherent ordering, where color is used only to distinguish categories
Matplotlib ships with 4 perceptually uniform color maps which are the recommended color maps for sequential data:
Colormap Description infernoperceptually uniform shades of black-red-yellowmagmaperceptually uniform shades of black-red-whiteplasmaperceptually uniform shades of blue-red-yellowviridisperceptually uniform shades of blue-green-yellowThe following colormaps are based on the ColorBrewer color specifications and designs developed by Cynthia Brewer:
ColorBrewer Diverging (luminance is highest at the midpoint, and decreases towards differently-colored endpoints):
Colormap Description BrBGbrown, white, blue-greenPiYGpink, white, yellow-greenPRGnpurple, white, greenPuOrorange, white, purpleRdBured, white, blueRdGyred, white, grayRdYlBured, yellow, blueRdYlGnred, yellow, greenSpectralred, orange, yellow, green, blueColorBrewer Sequential (luminance decreases monotonically):
Colormap Description Blueswhite to dark blueBuGnwhite, light blue, dark greenBuPuwhite, light blue, dark purpleGnBuwhite, light green, dark blueGreenswhite to dark greenGreyswhite to black (not linear)Orangeswhite, orange, dark brownOrRdwhite, orange, dark redPuBuwhite, light purple, dark bluePuBuGnwhite, light purple, dark greenPuRdwhite, light purple, dark redPurpleswhite to dark purpleRdPuwhite, pink, dark purpleRedswhite to dark redYlGnlight yellow, dark greenYlGnBulight yellow, light green, dark blueYlOrBrlight yellow, orange, dark brownYlOrRdlight yellow, orange, dark redColorBrewer Qualitative:
(For plotting nominal data,
ListedColormap
is used, notLinearSegmentedColormap
. Different sets of colors are recommended for different numbers of categories.)- Accent
- Dark2
- Paired
- Pastel1
- Pastel2
- Set1
- Set2
- Set3
A set of colormaps derived from those of the same name provided with Matlab are also included:
Colormap Description autumnsequential linearly-increasing shades of red-orange-yellowbonesequential increasing black-white color map with a tinge of blue, to emulate X-ray filmcoollinearly-decreasing shades of cyan-magentacoppersequential increasing shades of black-copperflagrepetitive red-white-blue-black pattern (not cyclic at endpoints)graysequential linearly-increasing black-to-white grayscalehotsequential black-red-yellow-white, to emulate blackbody radiation from an object at increasing temperatureshsvcyclic red-yellow-green-cyan-blue-magenta-red, formed by changing the hue component in the HSV color spacejeta spectral map with dark endpoints, blue-cyan-yellow-red; based on a fluid-jet simulation by NCSA [1]pinksequential increasing pastel black-pink-white, meant for sepia tone colorization of photographsprismrepetitive red-yellow-green-blue-purple-…-green pattern (not cyclic at endpoints)springlinearly-increasing shades of magenta-yellowsummersequential linearly-increasing shades of green-yellowwinterlinearly-increasing shades of blue-greenA set of palettes from the Yorick scientific visualisation package, an evolution of the GIST package, both by David H. Munro are included:
Colormap Description gist_earthmapmaker’s colors from dark blue deep ocean to green lowlands to brown highlands to white mountainsgist_heatsequential increasing black-red-orange-white, to emulate blackbody radiation from an iron bar as it grows hottergist_ncarpseudo-spectral black-blue-green-yellow-red-purple-white colormap from National Center for Atmospheric Research [2]gist_rainbowruns through the colors in spectral order from red to violet at full saturation (like hsv but not cyclic)gist_stern“Stern special” color table from Interactive Data Language softwareOther miscellaneous schemes:
Colormap Description afmhotsequential black-orange-yellow-white blackbody spectrum, commonly used in atomic force microscopybrgblue-red-greenbwrdiverging blue-white-redcoolwarmdiverging blue-gray-red, meant to avoid issues with 3D shading, color blindness, and ordering of colors [3]CMRmap“Default colormaps on color images often reproduce to confusing grayscale images. The proposed colormap maintains an aesthetically pleasing color image that automatically reproduces to a monotonic grayscale with discrete, quantifiable saturation levels.” [4]cubehelixUnlike most other color schemes cubehelix was designed by D.A. Green to be monotonically increasing in terms of perceived brightness. Also, when printed on a black and white postscript printer, the scheme results in a greyscale with monotonically increasing brightness. This color scheme is named cubehelix because the r,g,b values produced can be visualised as a squashed helix around 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-whiterainbowspectral purple-blue-green-yellow-orange-red colormap with diverging luminanceseismicdiverging blue-white-rednipy_spectralblack-purple-blue-green-yellow-red-white spectrum, originally from the Neuroimaging in Python projectterrainmapmaker’s colors, blue-green-yellow-brown-white, originally from IGOR ProThe following colormaps are redundant and may be removed in future versions. It’s recommended to use the names in the descriptions instead, which produce identical output:
Colormap Description gist_grayidentical to graygist_yargidentical to gray_rbinaryidentical to gray_rspectralidentical to nipy_spectral [5]
- Matplotlib API解释说明
- JAVA-API解释说明
- matplotlib的legend函数解释说明
- 中国天气网天气API参数详细解释说明
- matplotlib的plot函数说明
- Hash 的解释说明
- xsd的解释说明
- ./Configure参数解释说明
- xsd的解释说明
- xsd的解释说明
- saas相关说明解释
- enum的解释说明
- 解释器文件说明
- 完整LUT解释说明
- USB一些解释说明
- 虚函数解释说明
- java math API 解释
- Jfreechart中文API解释
- SQL Server 批量插入数据的两种方法
- 最近项目用到Dubbo框架,临时抱佛脚探讨一下
- optparse模块OptionParser学习
- 嵌入式Uboot,通过tftp进行内核镜像的加载及flash写入
- 全文搜索引擎ElasticSearch新手实战教程
- Matplotlib API解释说明
- Android------Binder 开始篇
- jmeter+ant+jenkins
- Javascript面向对象编程(二):构造函数的继承
- 史上最好记的事件分发机制
- 基于ssh和wsadmin的远程websphere部署
- pyecharts和matplotlib:基于python柱状图可视化
- Android 判断当前系统语言
- RBF or Fuzzy &pid