您可以在Python的单个图形窗口中循环浏览多个图吗?

时间:2018-06-27 16:09:08

标签: python matplotlib figure

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

如果在这里的其他地方提出了这个问题,请指出我的方向,然后我将结束这个问题。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

根据评论部分的建议,您可以使用 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)