【发布时间】:2015-04-01 11:58:21
【问题描述】:
我正在尝试调整子图中的两个数字的大小。基本上,我想要一个温度曲线为 111,压力曲线为 211 的子图。但是,我希望压力数字小于温度数字。如果没有相当复杂的 gridspec 库,这可能吗?我有以下代码:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# ------Pressure------#
df1 = pd.DataFrame.from_csv('Pressure1.csv',index_col = None)
df1['P'] = df1['P'].str.split('.').str[:-1].str.join(',').str.replace(',', '.').astype(np.float64)
a = df1['T']
a /= 2900 # Convert milliseconds to hours
initial_time = 0
a += initial_time - min(a)
b = df1['P']
b -=+1 #convert from volts to bar
# ------- Temperature----------#
df = pd.DataFrame.from_csv('Temperature1.csv',index_col = None)
w = df['Time']
w /= 3600000 # Convert milliseconds to hours
initial_time = 0
w += initial_time - min(w)
x = df['Input 1']
y = df['Input 2']
z = df['Input 3']
#----subplot----#
plt.subplot(1,1,1)
figsize(20,10)
plt.plot(w,x, label = "Top_sensor")
plt.plot(w,y, label = "Mid_sensor")
plt.plot(w,z, label = 'Bot_sensor')
plt.title('Temperature')
plt.xlabel('Time(Hours)')
plt.ylabel('Temperature (K)')
plt.ylim(70, 200)
plt.xlim(0, 12, 1)
plt.show()
plt.subplot(2,1,1)
figsize(20,3)
plt.plot(a,b)
plt.title('Pressure_Monitoring')
plt.xlabel('Time(Hours)')
plt.ylabel('Pressure (Bar)')
plt.xlim(0, 12, 1)
plt.show()
查看我如何尝试更改每个子图中的 figsize。这是错误的方式吗?
好的,所以我已经设法获得了我想要的 gridspec。但是,我如何将两者结合起来?
import matplotlib.gridspec as gridspec
f = plt.figure()
gs = gridspec.GridSpec(2, 1,width_ratios=[20,10], height_ratios=[10,5])
ax1 = plt.subplot(gs[0])
ax2 = plt.subplot(gs[1])
plt.show()
【问题讨论】:
-
试试
ax1 = plt.subplot(gs[0, :])和ax2 = plt.subplot(gs[1, :])。 -
在使用自己的数据集时如何使用 ax1 和 ax2?
-
plt.set_axes(ax1)和plt.set_axes(ax2)? -
plt.axes(ax1) 工作 :) 谢谢。
标签: python matplotlib pandas subplot