當前位置:首頁 » 編程語言 » python折線圖

python折線圖

發布時間: 2022-01-08 20:46:01

python3 折線圖上如何顯示特殊數據

  • # encoding=utf-8

  • import matplotlib.pyplot as plt

  • # 月份

  • x1 = ['2017-01', '2017-02', '2017-03', '2017-04', '2017-05', '2017-06', '2017-07', '2017-08',

  • '2017-09', '2017-10', '2017-11', '2017-12']

  • # 體重

  • y1 = [86, 85, 84, 80, 75, 70, 70, 74, 78, 70, 74, 80]

  • # 設置畫布大小

  • plt.figure(figsize=(16, 4))

  • # 標題

  • plt.title("my weight")

  • # 數據

  • plt.plot(x1, y1, label='weight changes', linewidth=3, color='r', marker='o',

  • markerfacecolor='blue', markersize=20)

  • # 橫坐標描述

  • plt.xlabel('month')

  • # 縱坐標描述

  • plt.ylabel('weight')

  • # 設置數字標簽

  • for a, b in zip(x1, y1):

  • plt.text(a, b, b, ha='center', va='bottom', fontsize=20)

  • plt.legend()

  • plt.show()

Ⅱ python matplotlib 同時畫箱線圖和折線圖的問題

因為boxplot的x坐標默認從1開始!

Ⅲ python怎麼畫折線圖

一、環境准備

linux ubuntu 下需安裝下面三個包:

Numpy, Scipy,Matplotlib

分別輸入下面的代碼進行安裝:

[plain]view plain

  • pipinstallnumpy

  • pipinstallscipy

  • sudoapt-getinstallpython-matplotlib

  • 測試是否安裝成功

    [html]view plain

  • python

  • >>>importpylab

  • 如果沒有報錯則安裝成功

    二、開始畫圖

    1. 畫最簡單的直線圖

    代碼如下:

    [python]view plain

  • importnumpyasnp

  • importmatplotlib.pyplotasplt

  • x=[0,1]

  • y=[0,1]

  • plt.figure()

  • plt.plot(x,y)

  • plt.savefig("easyplot.jpg")

  • 結果如下:



Ⅳ python畫折線圖

#encoding=utf-8
importmatplotlib.pyplotasplt
frompylabimport*#支持中文
mpl.rcParams['font.sans-serif']=['SimHei']

names=['5','10','15','20','25']
x=range(len(names))
y=[0.855,0.84,0.835,0.815,0.81]
y1=[0.86,0.85,0.853,0.849,0.83]
#plt.plot(x,y,'ro-')
#plt.plot(x,y1,'bo-')
#pl.xlim(-1,11)#限定橫軸的范圍
#pl.ylim(-1,110)#限定縱軸的范圍
plt.plot(x,y,marker='o',mec='r',mfc='w',label=u'y=x^2曲線圖')
plt.plot(x,y1,marker='*',ms=10,label=u'y=x^3曲線圖')
plt.legend()#讓圖例生效
plt.xticks(x,names,rotation=45)
plt.margins(0)
plt.subplots_adjust(bottom=0.15)
plt.xlabel(u"time(s)鄰居")#X軸標簽
plt.ylabel("RMSE")#Y軸標簽
plt.title("Asimpleplot")#標題

plt.show()

Ⅳ python 畫折線圖加一個legend

importmatplotlib.pyplotasplt

plt.plot([1,2,4,1],label='line1')
plt.plot([3,1,2,3],label='line2')
plt.legend()

可以通過plot函數的label參數來設置,

然後需要調用一下legend()函數。

Ⅵ 怎麼用python做光滑折線圖,謝謝了,困擾我很多天了

參考python散點的平滑曲線化方法

Ⅶ python畫折線圖,麻煩幫忙看看

提示是說2017-01-01不能轉化為float數據,因為沒有你的數據,提供一個簡單的例子(兩條折線)
import matplotlib.pyplot as plt

x = [1,2,3]
y = [5,7,4]

x2 = [1,2,3]
y2 = [10,14,12]

plt.plot(x, y, label='First Line')
plt.plot(x2, y2, label='Second Line')

plt.xlabel('Plot Number')
plt.ylabel('Important var')
plt.title('Interesting Graph\nCheck it out')
plt.legend()
plt.savefig("test.png")

Ⅷ python繪折線圖(數據很多)很難看

數據使用前要清洗,去除無效數據。
如果這些數據都是有效數據,只是你不想顯示那些過份異常的數據,那麼,就進行去噪處理。
去噪分兩步:檢測噪點,噪點修正。
對於整體連續,總體范圍大的數據集,最簡單的檢測噪點的辦法就是鄰值法,對於第n取相鄰的k個值:p[n-k,],p[n-k+1]...p[n-1]

對它們加權平均,得到標准點,上下浮動一定范圍,如果p[k]不在這個范圍內就是異常點
對應的噪點修正可以使用類似的過程,局部噪點回歸法。
這些一般來說都不是很實現的東西,對於數據集結構的不同,沒有必要做成通用的包,所以你只有自己實現。

Ⅸ python怎麼畫曲線圖

# encoding=utf-8
import matplotlib.pyplot as plt
from pylab import * #支持中文
mpl.rcParams['font.sans-serif'] = ['SimHei']

names = ['5', '10', '15', '20', '25']
x = range(len(names))
y = [0.855, 0.84, 0.835, 0.815, 0.81]
y1=[0.86,0.85,0.853,0.849,0.83]
#plt.plot(x, y, 'ro-')
#plt.plot(x, y1, 'bo-')
#pl.xlim(-1, 11) # 限定橫軸的范圍
#pl.ylim(-1, 110) # 限定縱軸的范圍
plt.plot(x, y, marker='o', mec='r', mfc='w',label=u'y=x^2曲線圖')
plt.plot(x, y1, marker='*', ms=10,label=u'y=x^3曲線圖')
plt.legend() # 讓圖例生效
plt.xticks(x, names, rotation=45)
plt.margins(0)
plt.subplots_adjust(bottom=0.15)
plt.xlabel(u"time(s)鄰居") #X軸標簽
plt.ylabel("RMSE") #Y軸標簽
plt.title("A simple plot") #標題

plt.show()

Ⅹ 如何用python畫出折線圖

用pylab模塊的plot函數
pylab.plot(x,y)其中x y都是數組
就能畫出以x,y中元素為坐標的折線圖

熱點內容
淘寶助理上傳沒有圖片 發布:2024-05-13 09:57:40 瀏覽:994
php編譯so 發布:2024-05-13 09:55:47 瀏覽:41
如何架設雙線伺服器 發布:2024-05-13 09:34:34 瀏覽:757
androidjson數組解析 發布:2024-05-13 09:01:13 瀏覽:258
監控實時上傳 發布:2024-05-13 08:35:24 瀏覽:53
銀行卡密碼忘記如何用微信取錢 發布:2024-05-13 08:34:51 瀏覽:63
手機的內部存儲空間是什麼 發布:2024-05-13 08:27:16 瀏覽:150
我的世界角色伺服器在哪 發布:2024-05-13 08:26:22 瀏覽:882
用ip伺服器封號嗎 發布:2024-05-13 08:25:47 瀏覽:768
有可視化編程 發布:2024-05-13 08:09:26 瀏覽:848