我想用辅助轴在子图中绘制数据。我可以设置ylim,但它只影响辅助y轴(在右侧)。我找不到控制主y轴(左侧)上的ylim的方法。我希望主y轴的限值为[0,40],次y轴的限值为[0,100]。
#import matplotlib.pylab as plt
import numpy as np
import pandas as pd
import csv
import string
%pylab inline
%matplotlib inline
# READ IN FIRST CSV
espr = pd.read_csv('out.csv')
df_e = pd.DataFrame(espr)
#READ IN SECOND CSV
heat = pd.read_csv('heat.csv',encoding='ISO-8859-1',low_memory=False)
heat = heat[2:]
df_h = pd.DataFrame(heat,dtype='float64')
df_h = df_h.reset_index(drop=True)
#READ IN THIRD CSV
temp = pd.read_csv('temp.csv',encoding='ISO-8859-1',low_memory=False)
temp = temp[2:]
df_t = pd.DataFrame(temp,dtype='float64')
df_t = df_t.reset_index(drop=True)
# CONCATENATE DATAFRAMES
df_e = df_e[[' building:time step (-)', ' building:zone 01:air point:temperature (oC)', ' building:zone 05:air point:temperature (oC)']]
df_h = df_h[['TIME', 'Tdb_amb']]
df_t = df_t[['Tavg_diurn', 'Tavg_seas']]
sim = pd.concat([df_h, df_t, df_e],axis=1)
# SEPARATE DATA FOR PLOTTING
mar = sim[14160:21600]
这就是我遇到了一堵墙,我读过关于设置twinx()来设置不同轴的属性,但每当我尝试实现它时,它告诉我它不知道twinx是什么。
fig, axes = plt.subplots(nrows=2, ncols=1)
fig.set_figheight(25)
fig.set_figwidth(20)
mar[' building:zone 01:air point:temperature (oC)'].plot(ax=axes[0])
mar[' building:zone 05:air point:temperature (oC)'].plot(ax=axes[0])
mar['Tavg_diurn'].plot(secondary_y=True, ax=axes[0])
mar['Tavg_seas'].plot(secondary_y=True, ax=axes[0])
ylim([0,100])
fig.tight_layout()
2条答案
按热度按时间lmyy7pcs1#
如果
axes
是两个轴的数组,那么你可以这样做:或者使用
pyplot's twinx()
,你可以尝试:8wtpewkr2#
关键是这样的:
axes[0].right_ax.set_ylim(0,100)