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

繪制方法 <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)
繪制方法<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, andindex三個參數(shù),其中idex從1開始,代表了左上角的圖像
到此這篇關(guān)于matplotlib繪制兩點間連線的幾種方法實現(xiàn)的文章就介紹到這了,更多相關(guān)matplotlib 兩點間連線內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
tensorflow 用矩陣運算替換for循環(huán) 用tf.tile而不寫for的方法
今天小編就為大家分享一篇tensorflow 用矩陣運算替換for循環(huán) 用tf.tile而不寫for的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-07-07
在Django下測試與調(diào)試REST API的方法詳解
今天小編就為大家分享一篇在Django下測試與調(diào)試REST API的方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08
python中l(wèi)ist*n生成多維數(shù)組與for循環(huán)生成多維數(shù)組的區(qū)別說明
這篇文章主要介紹了python中l(wèi)ist*n生成多維數(shù)組與for循環(huán)生成多維數(shù)組的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-05-05
Python word實現(xiàn)讀取及導(dǎo)出代碼解析
這篇文章主要介紹了Python word實現(xiàn)讀取及導(dǎo)出代碼解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-07-07

