Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw the Line between two points by matplotlib

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to draw a line between two points in matplotlib. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

In order to find the method of connecting matplotlib between two points, this paper mainly introduces several methods of drawing the line between two points by matplotlib, as follows

Drawing method this article will disassemble several components of Matplotlib drawing through the simplest mode, and cover the following

1. Create a dataset

2. Create a canvas

3. Add data to canvas

4. Show the figureimport numpy as npimport matplotlib.pyplot as plt # create a datasetpoints = np.linspace (- 5,5,256) y1 = np.tanh (points) + 0.5y2 = np.sin (points)-0.2 # create a canvasfig, axe = plt.subplots (figsize= (7,3.5), dpi=300) # add data to canvas axe.plot (points, y1) axe.plot (points, y2) # show the figurefig.savefig ('output/to.png') plt.close (fig)

The drawing method uses pyplot to draw the image import matplotlib.pyplot as pltimport numpy as np x = np.linspace (- 3,3256) y = np.sin (x) plt.plot (x, y)

The drawing method uses the axes class to draw images

Use axes to draw a single image using subplot () and subplots (nrows,ncols) to draw multiple graphics

Import matplotlib.pyplot as pltimport numpy as np x = np.linspace (- 3,3256) y = np.sin (x) ax = plt.subplot () ax.plot (x, y)

The drawing method uses the figure class to draw the image import matplotlib.pyplot as pltimport numpy as np x = np.linspace (- 3,3256) y = np.sin (x) fig = plt.figure (dpi=300) ax = fig.add_subplot (111ax.plot (x, y) fig.savefig ('output/to.png') plt.close (fig))

Represents the position of the image. If you use subplots, there are nrows, ncols, and index three parameters, of which idex starts from 1, on behalf of the upper left corner of the image on "matplotlib how to draw a connection between two points" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report