问题描述
我在ipython笔记本中有子图.我可以使用mpld3
模块进行内联放大.但是,现在我只能放大一个矩形.由于我的应用程序的性质,我需要水平缩放.
I have subplots in an ipython notebook. I can zoom in inline using the mpld3
module. However, right now I can only zoom into a rectangle. Due to my application's nature I need horizontal zoom.
在matplotlib中是否有一种方法(使用光标)水平缩放?更好的是,我可以通过代码在没有任何键盘操作的情况下将缩放设置为水平吗?在Matlab中,我可以这样设置:
Is there a way to zoom horizontally (using your cursor) in matplotlib? Better yet can I set the zoom to be horizontal via code without any keyboard manipulation? In Matlab, I can do this by setting:
figure(1); h=zoom; set(h,'Motion','horizontal','Enable','on');
这是python中的一个最小示例:
Here is a minimal example in python:
%matplotlib inline
import matplotlib.pyplot as plt
import mpld3
import numpy as np
mpld3.enable_notebook()
x = np.arange(100)
y = np.sin(x)
z = np.cos(x)
ax1 = plt.subplot(2,1,1)
ax1.plot(x,y)
ax2 = plt.subplot(2,1,2, sharex=ax1)
ax2.plot(x,z)
推荐答案
我的建议是使用 Plotly ,非常适合在Jupyter中创建交互式绘图.
My suggestion would be to use Plotly, which is great to create interactive plots in Jupyter.
您可以通过 HERE 获得有关如何绘制时间序列的更多信息,以及有关的信息子图此处.这是我对您的数据所做的,希望它能满足您的要求!
You can get more info on how to plot time series with it HERE and info on subplots HERE. Here is what I made with your data, hopefully it does what you want!
%matplotlib inline
import plotly
from plotly import tools
import numpy as np
plotly.offline.init_notebook_mode() # run at the start of every notebook
x = np.arange(100)
y = np.sin(x)
z = np.cos(x)
trace1 = go.Scatter(x=x, y=y)
trace2 = go.Scatter(x=x, y=z)
fig = tools.make_subplots(rows=2, cols=1)
fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 2, 1)
fig['layout'].update(height=600, width=600)
plotly.offline.iplot(fig)
这篇关于ipython笔记本水平缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!