【发布时间】:2020-07-19 10:47:29
【问题描述】:
我想使用类似于 matlotlib 示例的 pandas 数据框在 seaborn 中获得一个具有两个以上不同 y 轴的图:https://matplotlib.org/examples/axes_grid/demo_parasite_axes2.html
由于它将在函数中使用,我希望灵活地选择要绘制 Pandas 数据框的数量和列。
不幸的是,Seaborn 似乎只移动了最后添加的比例。 这是我想要对 Seaborn 样本数据集执行的操作:
import matplotlib.colors as mcolors
import matplotlib.pyplot as plt
import seaborn as sns
df=sns.load_dataset("mpg")
df=df.loc[df['model_year']<78]
show=['mpg','displacement','acceleration']
sns.set(rc={'figure.figsize':(11.7,8.27)})
sns.scatterplot('weight',show[0],data=df.reset_index(),style='model_year')
del show[0]
k=1
off=0
for i in show:
a = plt.twinx()
a=sns.scatterplot('weight',i,data=df.reset_index(),ax=a, color=list(mcolors.TABLEAU_COLORS)[k],legend=False,style='model_year')
a.spines['right'].set_position(('outward', off))
a.yaxis.label.set_color(list(mcolors.TABLEAU_COLORS)[k])
k+=1
off+=60
我想创建一个可以灵活绘制不同列的函数。到目前为止,这对我来说似乎很复杂(不可能只做一个循环)。如果有好的方法,我也会选择。
【问题讨论】:
标签: python pandas plot plotly seaborn