seaborn:如何制作 tsplot 正方形

Dav*_*jad 2 python matplotlib seaborn

我想创建一个 tsplot,其中 x 和 y 轴的长度相同。换句话说,图形的纵横比应为 1。

这不起作用:

fig, ax = plt.subplots()
fig.set_size_inches(2, 2)
sns.tsplot(data=df, condition=' ', time='time', value='value', unit=' ', ax=ax)
Run Code Online (Sandbox Code Playgroud)

Nic*_*eli 6

您可以通过控制对象的aspect 参数来更改绘图的纵横比,matplotlib如下所示:

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

np.random.seed(22)
sns.set_style("whitegrid")

gammas = sns.load_dataset("gammas")
fig = plt.figure()
ax = fig.add_subplot(111, aspect=2)  #Use 'equal' to have the same scaling for x and y axes
sns.tsplot(time="timepoint", value="BOLD signal", unit="subject", 
           condition="ROI", data=gammas, ax=ax)
plt.tight_layout()
plt.show()
Run Code Online (Sandbox Code Playgroud)

图片