是否可以用seaborn绘制破损的轴图?

问题描述 投票:4回答:2

我需要用现有数据绘制一个破碎的x轴图(例如下图),我的问题是是否可以使用seaborn API来做到这一点?

enter image description here

python matplotlib plot axis seaborn
2个回答
1
投票

不像我想的那样漂亮但是很有效。

Output

%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)

1
投票

更严格的版本(也取代了弃用的tsplot)。可以通过wspace线中的plt.subplots_adjust(wspace=0, hspace=0)参数控制图之间的距离。

enter image description here

%matplotlib inline 
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.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.subplots_adjust(wspace=0, hspace=0)
© www.soinside.com 2019 - 2024. All rights reserved.