有没有可能用seaborn绘制一个断轴图?

2024-03-29 10:07:42 发布

您现在位置:Python中文网/ 问答频道 /正文

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

enter image description here


Tags: 数据绘制seabornapi轴图
2条回答

更紧凑的版本(也替换了不推荐的tsplot)。{{{cd2>通过参数cd2}之间的距离来绘制。在

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)

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

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)

相关问题 更多 >