BlandAltman绘图将x轴移动到y=0

2024-09-30 03:24:51 发布

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

抱歉,如果这是一个重复的问题,我找不到任何代码,为我工作(仍然很新的这个!)你知道吗

我想移动x轴使其与y=0对齐,谢谢!你知道吗

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

values = pd.read_csv(r'C:\Project\Mech_Data.csv', index_col=0)
g = sns.lmplot(x="mean", y="difference", hue="Group", markers=["o", "x"], data=values, palette=colors, fit_reg=False, legend=False)
plt.xlim(xmin=0)

plt.plot([0, 1400],[127.5461,127.5461], linewidth=2, color='#f1e4d1',linestyle=':') #mean
plt.plot([0, 1400],[-217.3879288,-217.3879288], linewidth=2, color='#f1e4d1',linestyle='-.') #-SD
plt.plot([0, 1400],[472.4801288,472.4801288], linewidth=2, color='#f1e4d1',linestyle='-.') #+SD

leg = plt.legend(loc='upper left')
leg.get_frame().set_edgecolor('b')

plt.title('Bland-Altman', loc='left', fontsize=12, fontweight=0, color='#512443')
plt.xlabel('Mean')
plt.ylabel('Difference')
plt.tight_layout()

plt.show()

Output plot


Tags: csvimportfalseplotaspltsdmean
1条回答
网友
1楼 · 发布于 2024-09-30 03:24:51

您需要在plt.show()调用之前添加以下行。你知道吗

# get the axis 
ax = plt.gca()

# enforce placement of x-axis at y=0
# option 1)
ax.spines['bottom'].set_position('zero')

# option 2)
ax.spines['bottom'].set_position(('data', 0.))

相关问题 更多 >

    热门问题