【发布时间】:2021-05-04 12:29:45
【问题描述】:
我正在尝试绘制数据(见下文)。 x 轴为 company_name,y 轴为 status_mission_2_y,另一个 y_axis 为百分比。我尝试过使用 twinx() 函数,但我无法让它工作。
请问您能帮忙吗?提前致谢!
def twinplot(data):
x_ = data.columns[0]
y_ = data.columns[1]
y_2 = data.columns[2]
data1 = data[[x_, y_]]
data2 = data[[x_, y_2]]
plt.figure(figsize=(15, 8))
ax = sns.barplot(x=x_, y=y_, data=data1)
ax2 = ax.twinx()
g2 = sns.barplot(x=x_, y=y_2, data=data2, ax=ax2)
plt.show()
data = ten_company_missions_failed
twinplot(data)
| company_name | percentage | status_mission_2_y |
|---|---|---|
| EER | 1 | 1 |
| Ghot | 1 | 1 |
| Trv | 1 | 1 |
| Sandia | 1 | 1 |
| Test | 1 | 1 |
| US Navy | 0.823529412 | 17 |
| Zed | 0.8 | 5 |
| Gov | 0.75 | 4 |
| Knight | 0.666666667 | 3 |
| Had | 0.666666667 | 3 |
【问题讨论】:
标签: python matplotlib seaborn yaxis twinx