java调python画图_Python Matplotlib plot 绘图
1、繪制x和y點(diǎn)
plot()函數(shù)用于在圖中繪制點(diǎn)(標(biāo)記)。
默認(rèn)情況下,plot()函數(shù)在點(diǎn)到點(diǎn)之間畫一條線。
該函數(shù)具有用于在圖中指定點(diǎn)的參數(shù)。
參數(shù)1是一個(gè)數(shù)組,其中包含x軸上的點(diǎn)。
參數(shù)2是一個(gè)包含y軸上的點(diǎn)的數(shù)組。
如果需要繪制從(1,3)到(8,10)的線,則必須將兩個(gè)數(shù)組[1,8]和[3,10]傳遞給plot函數(shù)。
例如:
在圖中從位置(1、3)到位置(8、10)畫一條線:import matplotlib.pyplot as plt
import numpy as np
xpoints = np.array([1, 8])
ypoints = np.array([3, 10])
plt.plot(xpoints, ypoints)
plt.show()
Result:
x軸是水平軸.y軸是垂直軸。
2、繪制標(biāo)記
要僅繪制標(biāo)記,可以使用快捷方式字符串表示法參數(shù)'o',即'rings'。
例如:
在圖中繪制兩個(gè)點(diǎn),一個(gè)在位置(1、3),一個(gè)在位置(8、10):import matplotlib.pyplot as plt
import numpy as np
xpoints = np.array([1, 8])
ypoints = np.array([3, 10])
plt.plot(xpoints, ypoints, 'o')
plt.show()
Result:
3、繪制多個(gè)點(diǎn)(Multiple Points)
您可以根據(jù)需要繪制任意數(shù)量的點(diǎn),只需確保兩個(gè)軸上的點(diǎn)數(shù)相同即可。
例如:
在圖中從位置(1,3)到(2,8)然后到(6,1),最后到位置(8,10)畫一條線:import matplotlib.pyplot as plt
import numpy as np
xpoints = np.array([1, 2, 6, 8])
ypoints = np.array([3, 8, 1, 10])
plt.plot(xpoints, ypoints)
plt.show()
Result:
4、使用默認(rèn)x軸上的點(diǎn)
如果我們未在x軸上指定點(diǎn),則它們將獲得默認(rèn)值0、1、2、3(等),具體取決于y點(diǎn)的長度。
因此,如果我們采用與上述相同的示例,并省略x點(diǎn),則該圖將如下所示:
例如:
沒有x點(diǎn)的繪圖:import matplotlib.pyplot as plt
import numpy as np
ypoints = np.array([3, 8, 1, 10, 5, 7])
plt.plot(ypoints)
plt.show()
Result:
上例中的x點(diǎn)為[0、1、2、3、4、5]。
總結(jié)
以上是生活随笔為你收集整理的java调python画图_Python Matplotlib plot 绘图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python倒排索引实现_倒排索引原理和
- 下一篇: python字典合并几种方式对比,Pyt