可视化图形(三):折线/曲线图-plot()
生活随笔
收集整理的這篇文章主要介紹了
可视化图形(三):折线/曲线图-plot()
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
- 官方文檔:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html?highlight=pyplot plot#matplotlib.pyplot.plot
plot(x, y, format_string, **kwargs)
| x | x軸數據 |
| y | y軸數據 |
| format_string | 控制曲線的格式字符串,由顏色字符、風格字符和標記字符組成 |
| **kwargs | 第2組或更多的(x, y, format_string) |
| label | 設置標簽 |
| linewidth | 線條寬度 |
| antialiased | 抗鋸齒,False(關閉)和True(打開) |
示例:
import numpy as np import matplotlib as mpl import matplotlib.pyplot as pltfig = plt.figure() #創建Figure#子圖1:折線圖 ax1 = fig.add_subplot(231) x = [1, 2, 3, 4] y = [3, 5, 10, 25] plt.plot(x, y, marker = 'o') plt.sca(ax1)#子圖2:曲線圖 - sin() ax2 = fig.add_subplot(232) m = np.arange(-5.0, 5.0, 0.02) #500個間隔相等的點 n = np.sin(m) plt.xlim(-2.5, 2.5) #設置x軸范圍 plt.ylim(-1, 1) #設置y軸范圍 plt.plot(m, n, '--') plt.grid(True) #顯示網格線 plt.sca(ax2)#子圖3:兩條折線圖 ax3 = fig.add_subplot(233) plt.plot([1,2,3], [1,2,3], 'go-', label = 'line1', linewidth = 2, antialiased = False) plt.plot([1,2,3], [1,4,9], 'rs--', label = 'line2') plt.axis([0, 4, 0, 10]) #設置x軸范圍0~4,y軸范圍0~10 plt.legend() #顯示標簽 plt.sca(ax3)總結
以上是生活随笔為你收集整理的可视化图形(三):折线/曲线图-plot()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 属性总结(四):linestyle
- 下一篇: 005 反转单链表(迭代递归)