python画双y轴图像的示例代码

今天小编就为大家分享一篇python画双y轴图像的示例代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

很多时候可能需要在一个图中画出多条函数图像,但是可能y轴的物理含义不一样,或是数值范围相差较大,此时就需要双y轴。

matplotlib和seaborn都可以画双y轴图像。

一个例子:

 import seaborn as sns import matplotlib.pyplot as plt # ax1 for KDE, ax2 for CDF f, ax1 = plt.subplots() ax1.grid(True) # ax1.set_ylim(0, 1) ax1.set_ylabel('KDE') ax1.set_xlabel('DATA') ax1.set_title('KDE + CDF') ax1.legend(loc=2) sns.kdeplot(data, ax=ax1, lw=2, label='KDE') # KDE ax2 = ax1.twinx() # the reason why it works ax2.set_ylabel('CDF') ax2.legend(loc=1) ax2.hist(data, bins=50, cumulative=True, normed=True, histtype='step', color='red', lw=2, label='CDF') # CDF plt.show() 

以上就是python画双y轴图像的示例代码的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python