In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to call the figure () function in the pyplot module to deal with figure graphic objects in Matplotlib. In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations." I hope you can read it carefully and be able to achieve something!
In Matplotlib, the core idea of object-oriented programming is to create graphical objects (figure object). Other methods and properties are called through graphical objects, which helps us to better handle multiple canvases. In this process, pyplot is responsible for generating drawing objects and adding one or more axes objects (that is, the drawing area) through that object.
Matplotlib provides the matplotlib.figure graphics class module, which contains methods for creating graphical objects. Instantiate the figure object by calling the figure () function in the pyplot module.
As follows:
From matplotlib import pyplot as plt# creates drawing objects fig = plt.figure ()
The parameter values of this function are as follows:
Parameter figsize specifies the size of the canvas, (width, height), in inches. Dpi specifies the resolution of the drawing object, that is, how many pixels per inch, with a default value of 80. Facecolor background color. Dgecolor border color. Whether the frameon displays the border.
Let's create a blank canvas using figure ():
Fig = plt.figure ()
We use add_axes () to add the axes axis field to the canvas.
As follows:
Ax=fig.add_axes ([0re0re1pl])
The parameter value of add_axes () is a sequence in which the four numbers correspond to the left, bottom, width, and height of the graph, and each number must be between 0 and 1.
Set the label and title of the x and y axes, as follows:
Ax.set_title ("sine wave") ax.set_xlabel ('angle') ax.set_ylabel (' sine')
Call the plot () method of the axes object to draw the x and y arrays:
Ax.plot (XBI y)
The complete code is as follows:
From matplotlib import pyplot as pltimport numpy as npimport mathx = np.arange (0,0,0.05,0.05) y = np.sin (x) fig = plt.figure () ax = fig.add_axes ([0maije 1]) ax.plot (xmemy) ax.set_title ("sine wave") ax.set_xlabel ('angle') ax.set_ylabel (' sine') plt.show ()
The output is as follows:
Run the program in Jupyter Notebook and the result is as follows:
This is the end of the content of "how to call the figure () function in the pyplot module to deal with figure graphic objects in Matplotlib. Thank you for reading." If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.