【问题标题】:Can you cycle through multiple plots in a single figure window in Python?您可以在 Python 的单个图形窗口中循环浏览多个绘图吗?
【发布时间】:2018-06-27 16:09:07
【问题描述】:

我试图弄清楚如何在一个图中绘制多个图,但 NOT 使用子图和 NOT 在同一轴上。本质上,我想做的是,例如,分别绘制sinecosinetangent。它们都在同一个图形窗口中,您可以使用箭头键在不同的图形之间切换。我想象它需要将它们存储在列表或数组中。

如果这里的其他地方有人问过这个问题,请向我指出那个方向,我会结束这个问题。

感谢您的帮助!

【问题讨论】:

  • 您可以查看menubutton 等小部件。就个人而言,我认为bokeh 在交互式绘图方面比 matplotlib 效果更好。

标签: python matplotlib figure


【解决方案1】:

按照 cmets 部分的建议,您可以使用 bokeh。完全受bokeh documentation 启发,实现可能如下:

from bokeh.models.widgets import Panel, Tabs
from numpy import pi, arange, sin, cos
from bokeh.plotting import output_file, figure, show

output_file("slider.html")

x = arange(-2*pi, 2*pi, 0.1)
# your different functions
y1 = sin(x)
y2 = cos(x)

# building a tab per function/plot
p1 = figure(plot_width=300, plot_height=300)
p1.circle(x, y1, color="red")
tab1 = Panel(child=p1, title="sinus")

p2 = figure(plot_width=300, plot_height=300)
p2.circle(x, y2, color="blue")
tab2 = Panel(child=p2, title="cosinus")

# aggregating and plotting
tabs = Tabs(tabs=[tab1, tab2])
show(tabs)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-13
    • 2018-01-01
    • 2018-03-16
    • 1970-01-01
    • 1970-01-01
    • 2019-06-30
    • 2012-06-24
    • 2013-11-19
    相关资源
    最近更新 更多