matplotlib中的twiny()更改y轴比例 [英] twiny() in matplotlib changes the y-axis scale

查看:599
本文介绍了matplotlib中的twiny()更改y轴比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用matplotlib绘制某些数据,碰巧插入ax.twiny()模块会更改y轴的比例. 在我使用它之前:

Plotting some data with matplotlib, it happens that inserting the ax.twiny() module changes the scale of the y axis. Before I use it:

之后:

我想避免在y轴上手动插入限制.

I would like to avoid to insert manually the limits in the y-axis.

那为什么会发生这种情况,以及如何解决呢?

So why does this happen, and how to fix it?

推荐答案

那很奇怪.

我尝试使用twiny()选项,它不会更改比例:

I've tried using the twiny() option and it does not change the scale:

import numpy
import matplotlib.pylab as plt

x = numpy.linspace(0, 4. * numpy.pi, 1000)
y = numpy.cos(x)

fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax1.plot(x, y)
ax2 = ax1.twiny()

这给出了没有ax2 = ax1.twiny()的情况:

以及ax2 = ax1.twiny()

这也是您实现第二个x轴的方式吗?

Is this also the way you implement the second x-axis?

使用ax2,您将能够使用共享的y轴和第二个x轴绘制新数据.

Using ax2 you will be able to plot new data using the shared y-axis and the second x-axis.

希望这会有所帮助!

这篇关于matplotlib中的twiny()更改y轴比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆