Matplotlib:一条线,针对不同单位的两个相关 x 轴绘制?
我有一个 y 变量,我试图在图的顶部和底部针对两个相关的 x 轴绘制该变量(例如 y="立方体中的事物数量",x1="立方体的边长",x2="立方体的体积”)。我在 numpy 数组中有 y、x1、x2。我的x1和x2之间的关系是一对一且单调的,但并不简单,它们在不同的方向上增加,就像“边长”和“反体积”。我尝试过使用 twiny() 和 twin(),但这些似乎是为绘制不同的 y 变量而设计的。有什么想法吗?谢谢大家!
下面是我想要做的事情的一个例子,除了使用单行而不是符号。这个想法是,例如,sigma=0.4 和 M=2e15 对于一个点来说是等效且可互换的标签。
替代文本http://img580.imageshack.us/img580/4554/screenshotuy.png
I have one y variable, which I am trying to plot against two related x axes, on the top and bottom of the figure (e.g. y="number of things in cube", x1="side length of cube", x2="volume of cube"). I have y, x1, x2 in numpy arrays. The relationship between my x1 and x2 is one-to-one and monotonic, but not simple, and they increase in different directions, like "side length" and "inverse volume". I've tried using twiny() and twin(), but these seem to be designed for plotting different y variables. Any ideas? Thanks everyone!
Below is an example of the kind of thing I'm trying to do, except with a single line rather than symbols. The idea is that, say, sigma=0.4 and M=2e15 are equivalent and interchangeable labels for one point.
alt text http://img580.imageshack.us/img580/4554/screenshotuy.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于不同的 x 尺度,请使用 twiny()(将其视为“共享 y 轴”)。稍微改编自 matplotlib 文档 的示例:
如果您只想要第二个轴图第二个数据集不可见。
For different x-scales use
twiny()
(think of this as "shared y-axes"). An example slightly adapted from the matplotlib documentation:If you just wanted a second axis plot the second data set as invisible.
只是为了完整性:
存在“辅助轴”(matplotlib docs):
两个函数
需要在当前单位和不同单位之间进行适当的缩放。
文档中的代码:
这里,它们以度和弧度为单位显示正弦函数。
如果您没有明确定义的函数来在比例之间切换,您可以使用 numpy 插值:
Just for completeness:
There exists 'secondary axes' (matplotlib docs):
the two functions
need to give proper scaling between say, your current units, and different units.
Code from the documentation:
Here, they show the sinus function, in units of degrees and radians.
In case you do not have well defined functions to switch between scales, you can use numpy interpolation: