我已經繪製兩個y軸的圖表,現在想加兩個獨立的趨勢線每個在y地塊。如何添加多個趨勢線大熊貓
這是我的代碼:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
%matplotlib inline
amp_costs=pd.read_csv('/Users/Ampicillin_Costs.csv', index_col=None, usecols=[0,1,2])
amp_costs.columns=['PERIOD', 'ITEMS', 'COST PER ITEM']
ax=amp_costs.plot(x='PERIOD', y='COST PER ITEM', color='Blue', style='.', markersize=10)
amp_costs.plot(x='PERIOD', y='ITEMS', secondary_y=True,
color='Red', style='.', markersize=10, ax=ax)
至於如何繪製這兩個趨勢線該圖形的任何指導,將不勝感激!
看起來你在你的代碼就是這樣做的。問題是什麼?你得到了什麼樣的輸出?請爲我們製作一個最小可重複的示例。這使得以這種方式回答問題變得更加容易。 http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples –
什麼樣的趨勢線的?線性?滾動平均?什麼不在你的代碼中工作?你有什麼嘗試? –
@DemetriP線性...這個代碼工作正常但是我不能確定在哪裏,以增加2條趨勢線開始 - 1每組數據繪製的。 –