서브 Plot 내에서 두 개의 그림 크기를 조정하려고합니다. 기본적으로, 나는 111의 온도 프로파일과 211의 압력 프로파일을 가진 서브 플롯을 원합니다. 그러나 압력 수치를 온도 수치보다 작게하고 싶습니다. 다소 복잡한 gridspec lib없이 이것이 가능합니까? 다음 코드를 가지고 :matplotlib를 사용하여 서브 플로트 내에서 그림 크기를 조정하는 방법
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()
각 서브 플로트에서 무화과 크기를 어떻게 변경하려고하는지보십시오. 이것이 잘못된 방법입니까?
좋아요, 그래서 저는 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를 어떻게 사용합니까? – Joey
'plt.set_axes (ax1)'과'plt.set_axes (ax2)'? –