python怎么画excel里那种双y轴的图?

  统计/机器学习 数据可视化 Python    浏览次数:10804        分享
1

python怎么画excel里那种双y轴的图?类似这样的,左边和右边各一个纵轴



 

LeBron   2017-05-12 09:49



   1个回答 
6


import numpy as np

import matplotlib.pyplot as plt

x = np.arange(0, 10, 0.1)

y1 = x ** 2

y2 = - x ** 3

fig, ax1 = plt.subplots()

ax2 = ax1.twinx()

ax1.plot(x, y1, 'r-')

ax2.plot(x, y2, 'b-')

ax1.set_xlabel('X data')

ax1.set_ylabel('square of x', color='r')

ax2.set_ylabel('negative cube of x', color='b')

plt.title('double y-axes example')

plt.show()



SofaSofa数据科学社区DS面试题库 DS面经

五道口少年   2017-05-12 11:34

赞 - chaos0   2022-04-05 10:53


  相关讨论

matpltlib怎么给直方图加上拟合曲线?

pyplot的散点图怎么画空心的点?

怎么用Python画这种温度分布图

怎么给plt.subplot加一个主标题?

seaborn报错:regplot() got an unexpected keyword argument 'alpha'

如何用matplotlib在3D空间呈现x^2+y^2?

matplotlib一个画板上多个图叠加,如何决定图层上下?

如何用python画饼图?

画图的时候RuntimeError: Invalid DISPLAY variable

plt.scatter出现AttributeError: Unknown property markersize

  随便看看

pandas报错ValueError: Cannot convert non-finite values (NA or inf) to integer

主成分分析法(PCA)算是黑盒算法吗?

怎么把pandas dataframe中一列英文文本全部转成小写?

二元分类问题中经常提到的TP,TN,FN,FP都是什么意思?

python sklearn模型中random_state参数的意义