[英]Plotting secondary Y-axis using Panda?
我當前的代碼從csv文件中獲取一個列表,並列出供用戶選擇的標頭,以便進行繪圖。
import pandas as pd
df = pd.DataFrame.from_csv('log40a.csv',index_col=False)
from collections import OrderedDict
headings = OrderedDict(enumerate(df,1))
for num, heading in headings.items():
print("{}) {}".format(num, heading))
print ('Select X-Axis')
xaxis = int(input())
print ('Select Y-Axis')
yaxis = int(input())
df.plot(x= headings[xaxis], y= headings[yaxis])
我的第一個問題。 如何添加輔助Y軸。 我知道使用matplotlib首先創建一個圖形,然后用xaxis繪制第一個yaxis,然后對第二個yaxis做同樣的事情。 但是,我不確定如何在熊貓中做到這一點。 相似嗎?
我嘗試使用matplotlib來執行此操作,但它給了我一個錯誤:
fig1 = plt.figure(figsize= (10,10))
ax = fig1.add_subplot(211)
ax.plot(headings[xaxis], headings[yaxis], label='Alt(m)', color = 'r')
ax.plot(headings[xaxis], headings[yaxis1], label='AS_Cmd', color = 'blue')
錯誤:
ValueError: Unrecognized character a in format string
您需要使用要在y軸上繪制的列名稱創建一個數組。
如果用``,''分隔y列的示例
df.plot(x= headings[xaxis], y=headings[yaxis.split(",")], figsize=(15, 10))
要運行它,您將需要更改輸入法,以便它是一個數組而不是字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.