为了找到matplotlib在两个点之间连线的方法真是费了好大功夫,本文主要介绍了 matplotlib绘制两点间连线的几种方法,具体如下
绘制方法 <1>
本文将通过最简单的模式拆解Matplotlib绘图的几个组成部分,将cover以下内容
1. Create a dataset
2. Create a canvas
3. Add data to canvas
4. Show the figureimport numpy as np import matplotlib.pyplot as plt # create a dataset points = np.linspace(-5, 5, 256) y1 = np.tanh(points) + 0.5 y2 = np.sin(points) - 0.2 # create a canvas fig, axe = plt.subplots(figsize=(7, 3.5), dpi=300) # add data to canvas axe.plot(points, y1) axe.plot(points, y2) # show the figure fig.savefig('output/to.png') plt.close(fig)
绘制方法<2> 使用pyplot绘制图像
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-3, 3, 256) y = np.sin(x) plt.plot(x, y)
绘制方法<3> 使用axes类绘制图像
使用axes使用subplot()绘制单一图像,使用subplots( nrows,ncols )绘制多个图形
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-3, 3, 256) y = np.sin(x) ax = plt.subplot() ax.plot(x, y)
绘制方法<4> 使用figure类绘制图像
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-3, 3, 256) y = np.sin(x) fig = plt.figure(dpi=300) ax = fig.add_subplot(111) ax.plot(x, y) fig.savefig('output/to.png') plt.close(fig)
表示了图像的position。如果使用subplots,则有 nrows , ncols , and index 三个参数,其中idex从1开始,代表了左上角的图像到此这篇关于matplotlib绘制两点间连线的几种方法实现的文章就介绍到这了,更多相关matplotlib 两点间连线内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
查看更多关于matplotlib绘制两点间连线的几种方法实现的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did99609