Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6147461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:06:41+00:00 2026-05-23T19:06:41+00:00

I used matplotlib to create some plot, which depends on 8 variables. I would

  • 0

I used matplotlib to create some plot, which depends on 8 variables. I would like to study how the plot changes when I change some of them. I created some script that calls the matplotlib one and generates different snapshots that later I convert into a movie, it is not bad, but a bit clumsy.

  1. I wonder if somehow I could interact with the plot regeneration using keyboard keys to increase / decrease values of some of the variables and see instantly how the plot changes.

  2. What is the best approach for this?

  3. Also if you can point me to interesting links or a link with a plot example with just two sliders?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:06:42+00:00Added an answer on May 23, 2026 at 7:06 pm

    In addition to what @triplepoint mentioned, have a look at the slider widget.

    There’s an example on the matplotlib examples page. It’s a graphical slider bar rather than keyboard bindings, but it works quite well for what you want to do.

    Also note that to guarantee the sliders and buttons remain responsive and not garbage-collected, references to the objects (amp_slider, freq_slider, etc.) should be maintained by yourself.

    (I’m making this community wiki, as I’m just copy-pasting from the example. This particular example teaches bad habits (e.g. from pylab import *), but it gets the point across. The example has been fixed to avoid the use of pylab.)

    from numpy import pi, sin
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.widgets import Slider, Button, RadioButtons
    
    def signal(amp, freq):
        return amp * sin(2 * pi * freq * t)
    
    axis_color = 'lightgoldenrodyellow'
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    # Adjust the subplots region to leave some space for the sliders and buttons
    fig.subplots_adjust(left=0.25, bottom=0.25)
    
    t = np.arange(0.0, 1.0, 0.001)
    amp_0 = 5
    freq_0 = 3
    
    # Draw the initial plot
    # The 'line' variable is used for modifying the line later
    [line] = ax.plot(t, signal(amp_0, freq_0), linewidth=2, color='red')
    ax.set_xlim([0, 1])
    ax.set_ylim([-10, 10])
    
    # Add two sliders for tweaking the parameters
    
    # Define an axes area and draw a slider in it
    amp_slider_ax  = fig.add_axes([0.25, 0.15, 0.65, 0.03], facecolor=axis_color)
    amp_slider = Slider(amp_slider_ax, 'Amp', 0.1, 10.0, valinit=amp_0)
    
    # Draw another slider
    freq_slider_ax = fig.add_axes([0.25, 0.1, 0.65, 0.03], facecolor=axis_color)
    freq_slider = Slider(freq_slider_ax, 'Freq', 0.1, 30.0, valinit=freq_0)
    
    # Define an action for modifying the line when any slider's value changes
    def sliders_on_changed(val):
        line.set_ydata(signal(amp_slider.val, freq_slider.val))
        fig.canvas.draw_idle()
    amp_slider.on_changed(sliders_on_changed)
    freq_slider.on_changed(sliders_on_changed)
    
    # Add a button for resetting the parameters
    reset_button_ax = fig.add_axes([0.8, 0.025, 0.1, 0.04])
    reset_button = Button(reset_button_ax, 'Reset', color=axis_color, hovercolor='0.975')
    def reset_button_on_clicked(mouse_event):
        freq_slider.reset()
        amp_slider.reset()
    reset_button.on_clicked(reset_button_on_clicked)
    
    # Add a set of radio buttons for changing color
    color_radios_ax = fig.add_axes([0.025, 0.5, 0.15, 0.15], facecolor=axis_color)
    color_radios = RadioButtons(color_radios_ax, ('red', 'blue', 'green'), active=0)
    def color_radios_on_clicked(label):
        line.set_color(label)
        fig.canvas.draw_idle()
    color_radios.on_clicked(color_radios_on_clicked)
    
    plt.show()
    

    Example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Python 2.6, I used matplotlib to make some simple graphs. However, it is
I notice in several API's, that you may create a struct which is used
I used the LINQ to SQL designer in Visual Studio to create an object
Never used a cache like this before. The problem is that I want to
When used like this: import static com.showboy.Myclass; public class Anotherclass{} what's the difference between
I am having trouble installing matplotlib on mac os 10.6, so I used macports
Code Used: m_pButton->Create(LABC, WS_CHILD | WS_VISIBLE| BM_SETIMAGE,CRect(0,0,100,100),this,ID_BUTTON1); m_pButton->SetIcon(::LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON1))); //above Code show neither showing
I used to have a Buy Now button that would go through PayPal, and
I used to charts using core-plot framework, my requirement is draw vertical line as
used a script to rename a column which has caused a problem... sp_RENAME 'products.isvalid'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.