Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 设置X轴限制后填充绘图之间的区域_Python 3.x_Matplotlib_Plot - Fatal编程技术网

Python 3.x 设置X轴限制后填充绘图之间的区域

Python 3.x 设置X轴限制后填充绘图之间的区域,python-3.x,matplotlib,plot,Python 3.x,Matplotlib,Plot,当我在同一个图形上绘制两条曲线时,我很难设置X轴特定的限制 我的数据有两条曲线(渗透率和孔隙度),深度就像一个指数。所以我设法把它们画在同一张图上,并用一些帮助填充它们之间的区域。这是我的密码: df = pd.DataFrame({'DEPTH': [100, 150, 200, 250, 300, 350, 400, 450, 500, 550], 'PERMEABILITY': [1000, 800, 900, 600, 200, 250, 400, 300, 100, 20

当我在同一个图形上绘制两条曲线时,我很难设置X轴特定的限制

我的数据有两条曲线(渗透率和孔隙度),深度就像一个指数。所以我设法把它们画在同一张图上,并用一些帮助填充它们之间的区域。这是我的密码:

df = pd.DataFrame({'DEPTH': [100, 150, 200, 250, 300, 350, 400, 450, 500, 550],
       'PERMEABILITY': [1000, 800, 900, 600, 200, 250, 400, 300, 100, 200],
       'POROSITY': [0.30, 0.25, 0.15, 0.19, 0.15, 0.10, 0.15, 0.19, 0.10, 0.15]})

f, ax1 = plt.subplots()

ax1.set_xlabel('PERMEABILITY') 
ax1.set_ylabel('DEPTH')
ax1.set_ylim(df['DEPTH'].max(), df['DEPTH'].min())

ax1.plot(df['PERMEABILITY'], df['DEPTH'], color='red')
ax1.tick_params(axis='x', labelcolor='red')

ax2 = ax1.twiny()

ax2.set_xlabel('POROSITY')
ax2.plot(df['POROSITY'], df['DEPTH'], color='blue')
ax2.tick_params(axis='x', labelcolor='blue')

# convert POROSITY axis to PERMEABILITY
# value-min / range -> normalized POROSITY (normp)
# normp*newrange + newmin -> stretched POROSITY to PERMEABILITY
z=df['POROSITY']
x=df['PERMEABILITY']
nz=((z-np.min(z))/(np.max(z)-np.min(z)))*(np.max(x)-np.min(x))+np.min(x)

# fill between in green where PERMEABILITY is larger
ax1.fill_betweenx(df['DEPTH'],x,nz,where=x>=nz,interpolate=True,color='g')
# fill between in yellow where POROSITY is larger
ax1.fill_betweenx(df['DEPTH'],x,nz,where=x<=nz,interpolate=True,color='y')
plt.show()


有人能帮我吗?提前谢谢

计算的
nz
在两个x轴刻度之间转换。当您以不同的数量更改两个刻度时,您必须更改
nz
的计算。你需要弄清楚如何精确地做到这一点,但在这里,我只是盯着斜率和偏移量,直到它匹配

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

df = pd.DataFrame({'DEPTH': [100, 150, 200, 250, 300, 350, 400, 450, 500, 550],
       'PERMEABILITY': [1000, 800, 900, 600, 200, 250, 400, 300, 100, 200],
       'POROSITY': [0.30, 0.25, 0.15, 0.19, 0.15, 0.10, 0.15, 0.19, 0.10, 0.15]})

f, ax1 = plt.subplots()

ax1.set_xlabel('PERMEABILITY') 
ax1.set_ylabel('DEPTH')
ax1.set_ylim(df['DEPTH'].max(), df['DEPTH'].min())

ax1.plot(df['PERMEABILITY'], df['DEPTH'], color='red')
ax1.tick_params(axis='x', labelcolor='red')

ax2 = ax1.twiny()

ax2.set_xlabel('POROSITY')
ax2.plot(df['POROSITY'], df['DEPTH'], color='blue')
ax2.tick_params(axis='x', labelcolor='blue')

# convert POROSITY axis to PERMEABILITY
# value-min / range -> normalized POROSITY (normp)
# normp*newrange + newmin -> stretched POROSITY to PERMEABILITY
z=df['POROSITY']
x=df['PERMEABILITY']
nz=((z-np.min(z))/(np.max(z)-np.min(z)))*(np.max(x)-np.min(x))*0.6+np.min(x)+450
#                                                          slope ^      offset ^

ax1.set_xlim(0, 1500)
ax2.set_xlim(-0.10, 0.45)
# fill between in green where PERMEABILITY is larger
ax1.fill_betweenx(df['DEPTH'],x,nz,where=x>=nz,interpolate=True,color='g')
# fill between in yellow where POROSITY is larger
ax1.fill_betweenx(df['DEPTH'],x,nz,where=x<=nz,interpolate=True,color='y')
plt.show()
将熊猫作为pd导入
将matplotlib.pyplot作为plt导入
将numpy作为np导入
df=pd.DataFrame({'DEPTH':[100150200250300350400450500550],
“渗透性”:[1000800900600200250400300100200],
‘孔隙度’:[0.30,0.25,0.15,0.19,0.15,0.10,0.15,0.19,0.10,0.15]})
f、 ax1=plt.子批次()
ax1.set_xlabel(‘渗透性’)
ax1.set_ylabel('深度')
ax1.set_ylim(df['DEPTH'].max(),df['DEPTH'].min())
ax1.绘图(df['personality'],df['DEPTH'],color='red')
ax1.勾选参数(轴=x',标签颜色=red')
ax2=ax1.twny()
ax2.set_xlabel(‘孔隙度’)
ax2.绘图(df['porsity'],df['DEPTH'],color='blue')
ax2.勾选参数(轴=x',标签颜色=blue')
#将孔隙度轴转换为渗透率
#最小值/范围->标准化孔隙度(normp)
#normp*newrange+newmin->拉伸孔隙度到渗透率
z=df[‘孔隙度’]
x=df[‘渗透性’]
nz=((z-np.min(z))/(np.max(z)-np.min(z))*(np.max(x)-np.min(x))*0.6+np.min(x)+450
#坡度^偏移量^
ax1.set_xlim(01500)
ax2.设置\u xlim(-0.10,0.45)
#在渗透性较大的绿色区域填充
ax1.在nx(df['DEPTH'],x,nz,其中=x>=nz,interpolate=True,color='g')之间填充
#在孔隙度较大的地方用黄色填充

ax1.fill_betweenx(df['DEPTH'],x,nz,其中=xThanks,Don Kirby!你已经回答了我的问题,但如果你允许的话,我还有一个问题。我知道偏移量是df['DEPTH'].max()-df['DEPTH'].min(),斜率应该是这个偏移量除以(df['personality'][0]-df['personality']9]).是这样吗?.但是如果我把孔隙度的x轴颠倒过来,它应该像ax2。设置φxlim(0.45,-0.10),然后我就不知道如何改变这个斜率方程。你能告诉我吗?即使我把np.min(z)改成np.max(z)反之亦然,我不能得到精确的曲线图。或者我理解错了你的0.6值,你可以告诉我你是怎么看的
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

df = pd.DataFrame({'DEPTH': [100, 150, 200, 250, 300, 350, 400, 450, 500, 550],
       'PERMEABILITY': [1000, 800, 900, 600, 200, 250, 400, 300, 100, 200],
       'POROSITY': [0.30, 0.25, 0.15, 0.19, 0.15, 0.10, 0.15, 0.19, 0.10, 0.15]})

f, ax1 = plt.subplots()

ax1.set_xlabel('PERMEABILITY') 
ax1.set_ylabel('DEPTH')
ax1.set_ylim(df['DEPTH'].max(), df['DEPTH'].min())

ax1.plot(df['PERMEABILITY'], df['DEPTH'], color='red')
ax1.tick_params(axis='x', labelcolor='red')

ax2 = ax1.twiny()

ax2.set_xlabel('POROSITY')
ax2.plot(df['POROSITY'], df['DEPTH'], color='blue')
ax2.tick_params(axis='x', labelcolor='blue')

# convert POROSITY axis to PERMEABILITY
# value-min / range -> normalized POROSITY (normp)
# normp*newrange + newmin -> stretched POROSITY to PERMEABILITY
z=df['POROSITY']
x=df['PERMEABILITY']
nz=((z-np.min(z))/(np.max(z)-np.min(z)))*(np.max(x)-np.min(x))*0.6+np.min(x)+450
#                                                          slope ^      offset ^

ax1.set_xlim(0, 1500)
ax2.set_xlim(-0.10, 0.45)
# fill between in green where PERMEABILITY is larger
ax1.fill_betweenx(df['DEPTH'],x,nz,where=x>=nz,interpolate=True,color='g')
# fill between in yellow where POROSITY is larger
ax1.fill_betweenx(df['DEPTH'],x,nz,where=x<=nz,interpolate=True,color='y')
plt.show()