In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "what is the use of Matplotlib". The content is simple and easy to understand and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn this article "what is the use of Matplotlib".
Matplotlib is probably the most widely used suite in Python 2D-drawing. It allows users to easily graph data and provides a variety of output formats. Here we will explore common uses of matplotlib.
IPython and pylab patterns
IPython is an enhanced version of Python. It has been enhanced in naming inputs and outputs, using shell commands, and debugging capabilities. After we add the parameter-pylab to IPython at the command line terminal (--pylab after 0.12), we can draw interactively like Matlab or Mathematica.
pylab
Pylab is an interface to the matplotlib object-oriented drawing library. Its syntax is very similar to Matlab. That is, its main drawing commands have similar parameters to those of Matlab.
This article uses the example source code download:
Download
The download package contains two directories:
figures: store images generated by example code
scripts: store instance code
Elementary rendering
In this section, we'll go from simple to complex: first try to plot sine and cosine functions on the same graph with default configurations, then gradually beautify it.
The first step is to obtain the sine and cosine values:
frompylabimport*
X=np.linspace(-np.pi,np.pi,256,endpoint=True)
C,S=np.cos(X),np.sin(X)
X is a numpy array containing 256 values equally spaced from −π to +π. C and S are numpy arrays of cosine and sine values for these 256 values, respectively.
You can test the code in IPython interactive mode, or download the code (download links to these example diagrams) and execute:
pythonexercise_1.py
Use default configuration [source files]
Matplotlib's default configuration allows user customization. You can adjust most of the default settings: image size and resolution (dpi), line width, color, style, axes, axes, grid attributes, text and font attributes, etc. However, matplotlib's default configurations are good enough in most cases that you might want to change them on rare occasions.
importnumpyasnp
importmatplotlib.pyplotasplt
X=np.linspace(-np.pi,np.pi,256,endpoint=True)
C,S=np.cos(X),np.sin(X)
plt.plot(X,C)
plt.plot(X,S)
plt.show()
Details of default configuration [source file]
In the following code, we show the default configuration of matplotlib with comments, which contains all the configuration for drawing styles. The configuration in the code is exactly the same as the default configuration, and you can modify the values in interactive mode to see the effect.
#Import all the contents of matplotlib (nympy can be used with np)
frompylabimport*
#Create an 8*6 point plot and set the resolution to 80
figure(figsize=(8,6),dpi=80)
#Create a new 1*1 subgraph in which the next pattern is drawn in the first (and only) block
subplot(1,1,1)
X=np.linspace(-np.pi,np.pi,256,endpoint=True)
C,S=np.cos(X),np.sin(X)
#Draw cosine curves using blue, continuous lines with a width of 1 pixel
plot(X,C,color="blue",linewidth=1.0,line)
#Draw sinusoids using green, continuous lines with a width of 1 pixel
plot(X,S,color="green",linewidth=1.0,line)
#Set the upper and lower limits of the horizontal axis
xlim(-4.0,4.0)
#Set horizontal axis symbol
xticks(np.linspace(-4,4,9,endpoint=True))
#Set the upper and lower limits of the vertical axis
ylim(-1.0,1.0)
#Set vertical axis symbol
yticks(np.linspace(-1,1,5,endpoint=True))
#Save images at resolution 72
#savefig("exercice_2.png",dpi=72)
#Show on screen
show()
The above is all the content of "Matplotlib has what to use" this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.