Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.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 如果值超过matplotlib中的xlim,如何环绕绘图_Python_Matplotlib_Plot - Fatal编程技术网

Python 如果值超过matplotlib中的xlim,如何环绕绘图

Python 如果值超过matplotlib中的xlim,如何环绕绘图,python,matplotlib,plot,Python,Matplotlib,Plot,我正试图创建一个测井曲线图,在其中我设置了xlim条件。假设如果我的值超过xlim它将不会显示在绘图中,但我想要的是环绕,如果值大于xlimmax,则应环绕该值。也就是说,它应该显示在相同的y位置上,但不是从xlimmin出来 我的代码: _, ax = plt.subplots(1,1, figsize = (5,20)) ax2 = ax.twiny() ax.plot(df.GR, df.DEPT, 'red') ax2.plot(df.SP, df.DEPT, 'blue') ax.s

我正试图创建一个测井曲线图,在其中我设置了
xlim
条件。假设如果我的值超过
xlim
它将不会显示在绘图中,但我想要的是环绕,如果值大于
xlim
max,则应环绕该值。也就是说,它应该显示在相同的y位置上,但不是从
xlim
min出来

我的代码:

_, ax = plt.subplots(1,1, figsize = (5,20))
ax2 = ax.twiny()
ax.plot(df.GR, df.DEPT, 'red')
ax2.plot(df.SP, df.DEPT, 'blue')
ax.set_xlim(0, 150)
ax2.set_xlim(50, 90)
ax.set_xlabel('GR')
ax2.set_xlabel('SP')
ax.grid()
ax.set_xticks([0,15,30,45,60,75,90,105,120,135,150])
_.legend(['GR', 'SP'], bbox_to_anchor=(0.85,0.78), fontsize = 15)
所需绘图:

查看3900 m到3925 m之间的最后一个粗网格,您将看到当值超过
xlim
max时,它会缠绕在绘图的左侧,即
xlim
min侧


另外,我想复制与所需绘图中显示样式相同的图例。

对于“包裹”,您必须添加另一个轴并单独控制其限制。对于图例,没有优雅的解决方案,但您可以手动调整x轴标签的所有方面。例如:

import numpy as np
import matplotlib.pyplot as plt

# Make some fake data.
y = np.linspace(0, 1000)
x1 = np.sin(y / 100) + 1.1 + 0.5 * np.random.random(50)

# Make the plot.
fig, ax = plt.subplots(figsize=(3, 10))
ax_wrap = ax.twiny()
ax_wrap.axis('off')

# Plot x1 in blue.
ax.plot(x1, y)
ax.set_xlim(0, 1.5)
ax_wrap.plot(x1, y, '--')  # <-- This is the wrapped data.
ax_wrap.set_xlim(1.5, 3.0) # <-- Wrapped data's limits.

# Adjust the x-axis position and colour.
ax.set_xticks((0, 1.5))
ax.spines['top'].set_position(('outward', 10))
ax.spines['top'].set_color('C0')
ax.xaxis.set_ticks_position('top')
ax.xaxis.set_label_position('top')
ax.xaxis.set_label_coords(0.5, 1.03)
ax.set_xlabel('GR', color='C0', size=20)
ax.tick_params(axis='x', colors='C0', size=0)
将numpy导入为np
将matplotlib.pyplot作为plt导入
#制造一些假数据。
y=np.linspace(0,1000)
x1=np.sin(y/100)+1.1+0.5*np.random.random(50)
#制作情节。
图,ax=plt.子批次(图尺寸=(3,10))
ax_wrap=ax.twiny()
轴缠绕轴(“关闭”)
#用蓝色绘制x1。
轴图(x1,y)
ax.set_xlim(0,1.5)

ax_wrap.plot(x1,y,'-')#对于“wrap”,必须添加另一个轴并分别控制其限制。对于图例,没有优雅的解决方案,但您可以手动调整x轴标签的所有方面。例如:

import numpy as np
import matplotlib.pyplot as plt

# Make some fake data.
y = np.linspace(0, 1000)
x1 = np.sin(y / 100) + 1.1 + 0.5 * np.random.random(50)

# Make the plot.
fig, ax = plt.subplots(figsize=(3, 10))
ax_wrap = ax.twiny()
ax_wrap.axis('off')

# Plot x1 in blue.
ax.plot(x1, y)
ax.set_xlim(0, 1.5)
ax_wrap.plot(x1, y, '--')  # <-- This is the wrapped data.
ax_wrap.set_xlim(1.5, 3.0) # <-- Wrapped data's limits.

# Adjust the x-axis position and colour.
ax.set_xticks((0, 1.5))
ax.spines['top'].set_position(('outward', 10))
ax.spines['top'].set_color('C0')
ax.xaxis.set_ticks_position('top')
ax.xaxis.set_label_position('top')
ax.xaxis.set_label_coords(0.5, 1.03)
ax.set_xlabel('GR', color='C0', size=20)
ax.tick_params(axis='x', colors='C0', size=0)
将numpy导入为np
将matplotlib.pyplot作为plt导入
#制造一些假数据。
y=np.linspace(0,1000)
x1=np.sin(y/100)+1.1+0.5*np.random.random(50)
#制作情节。
图,ax=plt.子批次(图尺寸=(3,10))
ax_wrap=ax.twiny()
轴缠绕轴(“关闭”)
#用蓝色绘制x1。
轴图(x1,y)
ax.set_xlim(0,1.5)
轴包络图(x1,y,'-')#