Python 可以用seaborn绘制断轴图形吗?

Python 可以用seaborn绘制断轴图形吗?,python,matplotlib,plot,axis,seaborn,Python,Matplotlib,Plot,Axis,Seaborn,我需要用现有数据绘制一个断裂的x轴图(如下图),我的问题是是否可以使用API来实现这一点 没有我想要的那么漂亮,但很管用 更紧凑的版本(也替换了弃用的tsplot)。可以通过plt.subplot\u adjust(wspace=0,hspace=0)行中的wspace参数控制绘图之间的距离 %matplotlib内联 导入seaborn作为sns 将numpy作为np导入 将matplotlib.pyplot作为plt导入 x=np.linspace(0,20500) y=np.sin(x

我需要用现有数据绘制一个断裂的x轴图(如下图),我的问题是是否可以使用API来实现这一点


没有我想要的那么漂亮,但很管用

更紧凑的版本(也替换了弃用的
tsplot
)。可以通过
plt.subplot\u adjust(wspace=0,hspace=0)
行中的
wspace
参数控制绘图之间的距离

%matplotlib内联
导入seaborn作为sns
将numpy作为np导入
将matplotlib.pyplot作为plt导入
x=np.linspace(0,20500)
y=np.sin(x)
f、 (ax1,ax2)=plt.子批次(ncols=2,nrows=1,sharey=True)
ax=sns.lineplot(x=x,y=y,ax=ax1)
ax=sns.lineplot(x=x,y=y,ax=ax2)
ax1.set_xlim(0,6.5)
ax2.set_xlim(13.5,20)
plt.子批次调整(wspace=0,hspace=0)

是的,看这里:这对seaborn也适用吗?看起来seaborn plot自己生成plot对象,我可以替换这里生成的matplotlib对象:
f,(ax,ax2)=plt.subPlot(2,1,sharex=True)
因为seaborn完全构建在matplotlib之上,它肯定会工作。细节取决于您的实现。这里给出的答案对我来说非常有效,包括使用seaborn:
%matplotlib inline  # If you are running this in a Jupyter Notebook.
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt


x = np.linspace(0, 20, 500)
y = np.sin(x)

f, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, sharey=True)
ax = sns.tsplot(time=x, data=y, ax=ax1)
ax = sns.tsplot(time=x, data=y, ax=ax2)

ax1.set_xlim(0, 6.5)
ax2.set_xlim(13.5, 20)