Data Visualization in Python
matplotlib is python's most famous plotting library. It provides a set of command APIs similar to matlab, which is very suitable for interactive plotting. It can also be easily used as a drawing control.
Hands-on mini-programs:Draw a scatter plot of y=x^3
The sample code is as follows:
#coding=utf-8 import pylab as y # Introducing the pylab module x = (-10, 10, 100) # Setting the x-horizontal coordinate range and number of points (x, x*x*x,'or') # Generate images ax = () ['right'].set_color('none') ['top'].set_color('none') .set_ticks_position('bottom') ['bottom'].set_position(('data', 0)) .set_ticks_position('left') ['left'].set_position(('data', 0)) ax.set_yticks([-1000, -500, 500, 1000]) (() , () ) # Set the horizontal coordinates to the maximum and minimum values of x () #Show image
import pylab as y
The pylab introduced in the program belongs to a module of matplotlib, replacing its name with y. It includes many functions commonly used in the NumPy and pyplot modules, which facilitates quick calculations and plots, and is well suited for use in the IPython interactive environment.
(-10, 10, 100)
This is a function in numpy that returns equally spaced values, (a,b,c): a refers to the start position, b denotes the end position, and c denotes the number of points generated (default is 50)
Examples:
>>> (2.0, 3.0, num=5)
array([ 2. , 2.25, 2.5 , 2.75, 3. ])
(x, x*x*x,'or') #generate an image
Followed by 'o' to indicate a scatterplot
'r' sets the color to red, basically much like matlab does.
((), ())
This statement uses the xlim function to set the horizontal coordinate to the size of x
Example results:
summarize
Above is this article on Python combat small program using matplotlib module drawing code to share all the content, I hope to help you. Interested friends can continue to refer to other related topics on this site. If there are shortcomings, welcome to leave a message to point out. Thank you for the support of friends on this site!