matplotlib 海运重叠图中的比例尺差异

b4qexyjb  于 2023-03-03  发布在  其他
关注(0)|答案(1)|浏览(144)

我从海运热图中绘制了一个图,看起来是这样的:

我想绘制一条线,并在其上绘制散点图,其中包含以下数据:
| x_拟合|y_拟合|
| - ------|- ------|
| 无|0.16|
| 1个|0.01分|
| 第二章|0.08分|
| 三个|0.11|
| 四个|0.09|
| 五个|0.33|
| 六个|0.5分|
| 七|0.25|
但我绘制时y轴没有按比例:

代码为:

fig, ax = plt.subplots(1, 1, figsize=(10, 4))
ax = sns.heatmap(df_11, annot=False,cmap="Greens")
ax.scatter(x_fitted, y, label='Raw data', )
ax.plot(x_fitted, y_fitted, 'k', label='Fitted curve')
ax.set_xlabel('G')
ax.set_ylabel('G*-G')
ax.set_title('Calibrated Matrix')
ax.invert_yaxis()
fruv7luv

fruv7luv1#

我通过添加第二个轴解决了这个问题:

fig, ax = plt.subplots(1, 1, figsize=(10, 4))

sns.heatmap(df_11, annot=False, cmap="Greens", ax=ax)

ax.set_xlabel('G')
ax.set_title('Calibrated Matrix')
ax.invert_yaxis()

# Create a twin axis on the right side of the plot
ax2 = ax.twinx()
sns.scatterplot(df2.secondary, df2.mean_primary, label='Raw data', ax=ax2)
sns.lineplot(x_fitted, y_fitted, color='k', label='Fitted curve', ax=ax2)
ax2.set_ylabel('<G*>')

相关问题