Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Python Programming/matplotlib

From Wikibooks, open books for an open world
<Python Programming
Previous: pyFormexIndexNext: Natural Language Toolkit

matplotlib is a Python library that allows Python to be used like Matlab, visualizing data on the fly. It is able to create plots, histograms, power spectra, bar charts, errorcharts, scatterplots, etc. It can be used from normal Python and also from iPython.

Examples:

Plot a data series that represents the square function:

frommatplotlibimportpyplotaspltdata=[x*xforxinrange(20)]plt.plot(data)plt.show()

Plot a data series that represents the square function but in reverse order, by providing not only the series of the y-axis values but also the series of x-axis values:

frommatplotlibimportpyplotaspltdatax=list(range(20))datax.reverse()datay=[x*xforxinrange(20)]plt.plot(datax,datay)plt.show()

Plot the square function, setting the limits for the y-axis:

frommatplotlibimportpyplotaspltdata=[x*xforxinrange(20)]plt.ylim(-500,500)# Set limits of y-axisplt.plot(data)plt.show()

Links

[edit |edit source]
Previous: pyFormexIndexNext: Natural Language Toolkit
Retrieved from "https://en.wikibooks.org/w/index.php?title=Python_Programming/matplotlib&oldid=4384128"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp