我希望在seaborn中使用与matlotlib的示例类似的pandas数据帧,得到一个具有两个以上不同y轴的绘图:https://matplotlib.org/examples/axes_grid/demo_parasite_axes2.html
由于它将在函数中使用,我希望能够灵活地选择绘制数据帧的数量和列
不幸的是,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
我想创建一个可以灵活绘制不同列的函数。到目前为止,这似乎是相当复杂的阴谋对我来说(没有办法只是做一个循环)。如果有好办法的话,我也会跟你一起去
现在,我使用plotly实现了这一点
Plotly中实际上有一种很好的方法,您可以看到下图的代码示例,类似于this section of the docs中的matplotlib示例
相关问题 更多 >
编程相关推荐