Matplotlib/Pyplot:如何一起放大子图? [英] Matplotlib/Pyplot: How to zoom subplots together?

查看:775
本文介绍了Matplotlib/Pyplot:如何一起放大子图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将3轴加速度计时间序列数据(t,x,y,z)绘制在单独的子图中,我想将它们一起放大.也就是说,当我在一个图上使用缩放到矩形"工具时,当我释放鼠标时,所有三个图都一起缩放.

I have plots of 3-axis accelerometer time-series data (t,x,y,z) in separate subplots I'd like to zoom together. That is, when I use the "Zoom to Rectangle" tool on one plot, when I release the mouse all 3 plots zoom together.

以前,我只是使用不同的颜色在一个绘图上简单地绘制了所有3个轴.但这仅在少量数据时有用:我有超过200万个数据点,因此绘制的最后一个轴使其他两个点模糊.因此,需要单独的子图.

Previously, I simply plotted all 3 axes on a single plot using different colors. But this is useful only with small amounts of data: I have over 2 million data points, so the last axis plotted obscures the other two. Hence the need for separate subplots.

我知道我可以捕获matplotlib/pyplot鼠标事件(http://matplotlib.sourceforge.net/users/event_handling.html),并且我知道可以捕获其他事件(http://matplotlib.sourceforge.net/api/backend_bases_api.html#matplotlib.backend_bases.ResizeEvent),但我不知道如何知道在任何一个子图上请求了什么缩放,以及如何在其他两个子图上复制它.

I know I can capture matplotlib/pyplot mouse events (http://matplotlib.sourceforge.net/users/event_handling.html), and I know I can catch other events (http://matplotlib.sourceforge.net/api/backend_bases_api.html#matplotlib.backend_bases.ResizeEvent), but I don't know how to tell what zoom has been requested on any one subplot, and how to replicate it on the other two subplots.

我怀疑我已经掌握了一切,只需要最后一条宝贵的线索...

I suspect I have the all the pieces, and need only that one last precious clue...

-BobC

推荐答案

最简单的方法是在创建轴时使用sharex和/或sharey关键字:

The easiest way to do this is by using the sharex and/or sharey keywords when creating the axes:

from matplotlib import pyplot as plt

ax1 = plt.subplot(2,1,1)
ax1.plot(...)
ax2 = plt.subplot(2,1,2, sharex=ax1)
ax2.plot(...)

这篇关于Matplotlib/Pyplot:如何一起放大子图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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