I'm trying to resize two figures within a subplot. Basically, I want a subplot with a temperature profile at 111 and a pressure profile at 211. However, I want the pressure figure to be smaller than the temperature figure. is this possible without the rather complicated gridspec lib? I have the following code:
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()
See how I try to change the figsize in each subplot. Is this the wrong way?
Okay, so i've managed to get the gridspec i want. But, how do i combine the two?
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, :])andax2 = plt.subplot(gs[1, :]).plt.set_axes(ax1)andplt.set_axes(ax2)?