Skip to main content
 首页 » 编程设计

python之Matplotlib 复选框(上一个和下一个)

2024年10月24日7freeliver54

我创建了多个图形,但我不想一次全部显示,我该如何使用按钮或复选框?

当我点击下一步时,换成其他图形

我的代码,但这显示了 2 个数字,我不喜欢这样:

import matplotlib.pyplot as plt 
intervals = ['52, 57', '57, 62', '62, 67', '67, 72', '72, 77', '77, 82', '82, 87'] 
absolute = [3, 11, 23, 27, 10, 5, 1] 
pos = np.arange(len(absolute)) 
# figure with bars fi 
width = 1.0 
fig1= plt.figure() 
ax1 = plt.axes() 
ax1.plot(pos, absolute, '-', linewidth=2) 
 
 
# figure with lines fi 
fig2 = plt.figure() 
pos = np.arange(len(absolute)) 
x = np.linspace(0, 10) 
ax = plt.axes() 
ax.plot(pos, absolute, '--', linewidth=2) 
 
plt.show() 

非常感谢!

您好!

请您参考如下方法:

使用 Ipython(Jupyter notebook),这很容易看。 关键字 bool 是生成复选框所需的全部内容。如果单击它,它会更改值和绘图,如图所示。

import numpy as np 
import matplotlib.pyplot as plt 
from ipywidgets import * 
%matplotlib inline 
 
 
t = np.arange(100) 
f=0.01 
data = np.sin(2*np.pi*f*t) 
 
def plot(lines): 
    fig1= plt.figure() 
    ax = plt.axes() 
    if lines: 
        ax.plot(t,data, '-', linewidth=2) 
    else:  
        ax.plot(t,data, '.', linewidth=2) 
interact(plot, lines=bool())