最新国产好看的视频,伊人天堂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開始,代表了左上角的圖像

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

相關(guān)文章

最新評論

遂溪县| 洪湖市| 卢湾区| 沧州市| 韩城市| 北京市| 九龙县| 平顶山市| 海安县| 兴仁县| 敦煌市| 观塘区| 昌平区| 马尔康县| 东乌| 施甸县| 岳阳县| 伊宁市| 项城市| 酒泉市| 兴业县| 罗江县| 云龙县| 广西| 南澳县| 阿瓦提县| 东台市| 荆门市| 丘北县| 涪陵区| 荥经县| 邻水| 石棉县| 余江县| 聂荣县| 伊吾县| 舟山市| 沂南县| 新建县| 阳江市| 巴彦县|