Milor123 Milor123 - 1 year ago 228
Python Question

Matplotlib (previous and next view)

I've created multiple figures but I don't want to appear all at once, how could I use the buttons ? for example:


When I click in next, change for other figure

My code, but this show 2 figures, and I dont like this:

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)

Thank you very much!


Answer Source

Using an Ipython (Jupyter notebook) this is pretty easy and nice to look at. The keyword bool is all you need to generate a checkbox. If you click it, it changes the value and the plot as shown.

import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import *
%matplotlib inline

t = np.arange(100)
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)
        ax.plot(t,data, '.', linewidth=2)
interact(plot, lines=bool())     

enter image description here

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download