[英]Change colors of two y-axes with Seaborn?
My code is:我的代码是:
import seaborn as sns
import pandas as pd
df = pd.read_excel('data.xls','data')
sns.regplot(x='X var', y='Y var1',fit_reg=False, data=df)
ax2 = plt.twinx()
sns.regplot(x='X var', y='Y var2', ax=ax2, fit_reg=False,
color='r',data=df)
I would like "Y var1" title to be blue and the "Y var2" title to be red if possible.如果可能,我希望“Y var1”标题为蓝色,“Y var2”标题为红色。 Either this or a legend that indicates which scatter plot corresponds to which axes.
此图或指示哪个散点图对应于哪个轴的图例。
The solution I found was:我找到的解决方案是:
import seaborn as sns
import pandas as pd
df = pd.read_excel('data.xls','data')
ax1 = sns.regplot(x='X var', y='Y var1',fit_reg=False, data=df)
ax1.set_ylabel('Y var1', color='b')
ax2 = plt.twinx()
ax2.set_ylabel('Y var2', color='r')
ax3 = sns.regplot(x='X var', y='Y var2', ax=ax2, fit_reg=False,
color='r',data=df)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.