最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

matplotlib繪制兩點間連線的幾種方法實現(xiàn)

 更新時間:2022年03月07日 10:31:30   作者:津津小可愛  
本文主要介紹了matplotlib繪制兩點間連線的幾種方法實現(xiàn),主要介紹了4種方法,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

為了找到matplotlib在兩個點之間連線的方法真是費了好大功夫,本文主要介紹了 matplotlib繪制兩點間連線的幾種方法,具體如下

25bd872893d525be3eef175c36d91618.png

繪制方法 <1>

本文將通過最簡單的模式拆解Matplotlib繪圖的幾個組成部分,將cover以下內(nèi)容
1. Create a dataset
2. Create a canvas
3. Add data to canvas
4. Show the figure
import 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)

416678f59ed73e91b34b9187a032fcc4.png

繪制方法<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)

1cb3b0d6b617e18981a04ab78dcf521e.png

繪制方法<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)

1cb3b0d6b617e18981a04ab78dcf521e.png

繪制方法<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)

1cb3b0d6b617e18981a04ab78dcf521e.png

表示了圖像的position。如果使用subplots,則有 nrows, ncols, and index三個參數(shù),其中idex從1開始,代表了左上角的圖像

 到此這篇關于matplotlib繪制兩點間連線的幾種方法實現(xiàn)的文章就介紹到這了,更多相關matplotlib 兩點間連線內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

开封市| 海南省| 石屏县| 收藏| 营口市| 宜州市| 日喀则市| 中牟县| 抚顺县| 乐平市| 陵川县| 平果县| 禄丰县| 奉化市| 裕民县| 突泉县| 黄龙县| 泉州市| 五大连池市| 辉南县| 绥滨县| 孙吴县| 张家界市| 南漳县| 临清市| 舞钢市| 雅安市| 定远县| 双桥区| 永寿县| 故城县| 蒙山县| 岳普湖县| 大荔县| 高青县| 衡阳县| 陇南市| 武乡县| 邢台市| 清丰县| 寿宁县|