In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to use the visualization tool Matplotlib in Python, aiming at this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Matplotlib is a Python 2D drawing library and some basic 3D charts that can generate pictures in various formats. Matplotlib can be used for Python scripts, Python shell,Jupyter notebooks, Web application servers, and so on.
View Matplotlib version
> import matplotlib > matplotlib.__version__ '3.0.3'
When you call Matplotlib in Python, you usually use import matplotlib.pyplot to call the Matplotlib integrated quick drawing pyplot module.
Figure (entire image)
Before any drawing, you need a Figure object, which can be understood to mean that you need a drawing board to start drawing.
Import matplotlib.pyplot as plt fig = plt.figure ()
In Matplotlib, the entire image is a Figure object. A Figure object can contain one or more Axes objects, each of which is a drawing area with its own coordinate system.
Axes (axis)
After you have a Figure object, you need an axis before you paint. Without an axis, there is no drawing datum, so you need to add Axes. It can also be understood as paper that can really paint.
Ax = fig.add_subplot (111) ax.set (xlim= [0,5], ylim= [0,6], title='An Example Axes', ylabel='Y-Axis', xlabel='X-Axis') plt.show ()
The above code adds an Axes to a picture, and then sets the value range of the X axis and Y axis of the Axes, as well as some text information. The effect is as follows:
Under Matplotlib, a Figure object can contain multiple subgraphs (Axes), which can be quickly drawn using subplot (), which can be called as follows:
Subplot (numRows, numCols, plotNum)
The entire drawing area of the chart is divided into numRows rows and numCols columns
Each sub-area is then numbered from left to right and from top to bottom, and the number of the sub-area on the upper left is 1
The plotNum parameter specifies the area where the created Axes object is located
For the fig.add_subplot (111above), which adds Axes, the interpretation of the parameters generates an Axes object in the first row of the artboard in the first column * to prepare for painting.
Axes can also be generated by fig.add_subplot (2, 2, 1), and the first two parameters determine the partition of the panel.
If the numbers numRows, numCols, and plotNum are all less than 10, they can be abbreviated to an integer, for example, subplot (221) and subplot (2mem2mem1) are the same.
Subplot creates an axis object in the area specified by plotNum. If the newly created axis overlaps the previously created axis, the previous axis will be deleted.
Multiple Axes multiple subgraphs
The following generates all Axes at once:
A brief summary.
At the top is the canvas, which is called figure.
You can paint on different areas on the canvas, which are called subplot
Each sub-image area can be divided as follows:
Axis, that is, the XBI y axis
Tick is the scale of each axis.
Label is the label on the axis.
Title is the title of each subgraph.
Data is an image drawn by the input data
Matplotlib drawing demonstration code
The image is divided into 8 sub-regions, each of which draws a different image.
Import numpy as np import matplotlib.pyplot as plt x = [1 scatter 2 plt.pie 3 4] y = [3 pie 5 10 10 25] # create a subgraph plt.subplot (241) plt.plot (xmemy) plt.title ("plot") plt.subplot (242) plt.scatter (xMagere y) plt.title ("scatter") plt.subplot (243) plt.pie (y) plt.title ("pie") plt.subplot (244) plt.bar (x Y) plt.title ("bar") plt.subplot (245) plt.boxplot (y, sym= "o") plt.title ("box") # sin/cos image plt.subplot (246) x = np.linspace (0, np.pi) y_sin = np.sin (x) y_cos = np.cos (x) plt.plot (x, y_sin) plt.plot (x Y_cos) # gmurf-set line style and color plt.subplot (247) plt.plot (x, y_sin, 'gMurray') plt.title ("sin") # load local picture import matplotlib.image as mpimg img=mpimg.imread ('666.jpg') plt.subplot (248) plt.imshow (img) plt.title ("cool...") Plt.show () on how to use the visualization tool Matplotlib in Python to share the answer to the question here, I hope the above content can be of some help to you, if you still have a lot of doubts to solve, you can follow the industry information channel to learn more related knowledge.
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: 273
*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.