简体   繁体   English

带有第二个 y 轴的 Seaborn 图

[英]Seaborn plot with second y axis

i wanted to know how to make a plot with two y-axis so that my plot that looks like this :我想知道如何用两个 y 轴绘制一个图,以便我的图看起来像这样: 在此处输入图片说明

to something more like this by adding another y-axis :通过添加另一个 y 轴来实现更像这样的东西: 在此处输入图片说明

i'm only using this line of code from my plot in order to get the top 10 EngineVersions from my data frame :我只使用我的情节中的这行代码,以便从我的数据框中获取前 10 个 EngineVersions:

sns.countplot(x='EngineVersion', data=train, order=train.EngineVersion.value_counts().iloc[:10].index);

i wanted to know how to make a plot with two y-axis so that my plot that looks like this :我想知道如何绘制两个Y轴的图,这样我的图看起来像这样: 在此处输入图片说明

to something more like this by adding another y-axis :通过添加另一个y轴,可以更像这样: 在此处输入图片说明

i'm only using this line of code from my plot in order to get the top 10 EngineVersions from my data frame :我只是从我的情节中使用这一行代码,以便从我的数据框中获取前10个EngineVersions:

sns.countplot(x='EngineVersion', data=train, order=train.EngineVersion.value_counts().iloc[:10].index);

i wanted to know how to make a plot with two y-axis so that my plot that looks like this :我想知道如何绘制两个Y轴的图,这样我的图看起来像这样: 在此处输入图片说明

to something more like this by adding another y-axis :通过添加另一个y轴,可以更像这样: 在此处输入图片说明

i'm only using this line of code from my plot in order to get the top 10 EngineVersions from my data frame :我只是从我的情节中使用这一行代码,以便从我的数据框中获取前10个EngineVersions:

sns.countplot(x='EngineVersion', data=train, order=train.EngineVersion.value_counts().iloc[:10].index);

You could try this code to obtain a very similar image to what you originally wanted.您可以尝试使用此代码来获得与您最初想要的非常相似的图像。

import seaborn as sb
from matplotlib.lines import Line2D
from matplotlib.patches import Rectangle

x = ['1.1','1.2','1.2.1','2.0','2.1(beta)']
y = [1000,2000,500,8000,3000]
y1 = [3,4,1,8,5]
g = sb.barplot(x=x, y=y, color='blue')
g2 = sb.lineplot(x=range(len(x)), y=y1, color='orange', marker='o', ax=g.axes.twinx())
g.set_xticklabels(g.get_xticklabels(), rotation=-30)
g.set_xlabel('EngineVersion')
g.set_ylabel('Counts')
g2.set_ylabel('Detections rate')
g.legend(handles=[Rectangle((0,0), 0, 0, color='blue', label='Nontouch device counts'), Line2D([], [], marker='o', color='orange', label='Detections rate for nontouch devices')], loc=(1.1,0.8))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM