使用 s 时,轴标签与最右边的数字对齐



我在对齐 sns.jointplot 图形上的文本时遇到问题。x 和 y 标签被指定到最右边的数字而不是主图形。我找不到一种方法将它们仅归因于主要人物。

我的代码如下;

z = sns.jointplot(load[0:9500], priceerror[0:9500], kind='scatter', dropna = True, stat_func=None, 
size=7, ratio=3, xlim=(0,60000));
plt.rc("legend", fontsize=15)
plt.xlabel('Load (MW)')
plt.ylabel('Price Error (£/MWh)')
plt.tick_params(axis="both", labelsize=15)

rc 参数应该在受其影响的绘图命令之前设置,因此plt.rc("legend", fontsize=15)移动到顶部。

关节图返回一个JointGrid实例。这有一个set_axis_labels设置标签的方法。

最后,它提供轴作为ax_joint(以及ax_marg_yax_marg_x(。这些可用于使用通常的matplotlib方法进行进一步的操作。例如g.ax_joint.tick_params(..)用于修改即时报价参数。

import numpy as np;  np.random.seed(0)
import seaborn as sns
tips = sns.load_dataset("tips")
import matplotlib.pyplot as plt
plt.rc("legend", fontsize=14)
g = sns.jointplot(x="total_bill", y="tip", data=tips)
g.set_axis_labels('Load (MW)', u'Price Error (£/MWh)')
# alterntively g.ax_joint.set_ylabel('Price Error (£/MWh)')
g.ax_joint.tick_params(axis="both", labelsize=15)
plt.show()

最新更新