Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 MatplotLib Sliders
#1
Wondered if anyone can help. The following code creates a 64x64 heatmap.
I'd like to add two horizontal sliders A and B each scaled from -90 to +90
Next to each slider I'd like to show the value selected on each slider in a label.
I've tried several times but can't seem to get it to work. Thanks

import matplotlib.pyplot as plt
import numpy as np

a = np.random.random((64, 64))

plt.figure('My First GUI')

plt.imshow(a, cmap='gray', interpolation='nearest')
plt.show()
Quote
#2
I think this question fits more in the GUI forum.

D

Just to answer this anyway, here is what you wanted:
import matplotlib.pyplot as plt
from pylab import *
from matplotlib.widgets import Slider
import numpy as np

c = 0 
a = np.random.random((64, 64))
 
plt.figure('My First GUI')
plt.imshow(a, cmap='gray', interpolation='nearest')

axcolor = 'lightgoldenrodyellow'
axhte = axes([0.15, 0.04, 0.6, 0.03], facecolor=axcolor) #x,y,w,h
axhre = axes([0.15, 0.01, 0.65, 0.03], facecolor=axcolor)

sl1 = Slider(axhte, 'Slider1', -90, 90, valinit=1)
sl2 = Slider(axhre, 'Slider2', -90, 90, valinit=1)

def get_valS1(val):
    print("value of s1:",sl1.val)

def get_valS2(val):
    print("value of s2:",sl2.val)

sl1.on_changed(get_valS1)
sl2.on_changed(get_valS2)

plt.show()
Have a look here to see where I got it from: https://stackoverflow.com/questions/1106...tlib-chart

D
Quote
#3
Thanks DreamingInsanity, That works great. Sorry for posting in the wrong forum. I'll just continue here to keep this thread going but keep that in mind for future posts. I have a few comments/questions

1. One of the sliders appears to be longer than the other and i'm not sure why
2. How can i insert some vertical space between the heatmap and the sliders and between the sliders themselves?
3. I'd like the grayscale value of each pixel to change according to the formula:

Grayscale (pix x,y) = x*sin(Slider1 Value) + y* sin(Slider2 Value)

I'm not sure how many grayscale values there are but i'd also like to be able to apply the MOD function to limit the grayscale values

Any help greatly appreciated, Thanks
Quote
#4
As for the grayscale, I will work on it soon.

For the spacing if you look in my code on line 12, I have witten the comment '#x,y,w,h'. X is how far right the slider is from the left side of the screen. Y is how far the slider is from the bottom of the screen. To add a gap between two sliders, just change the Y value on them (the second value in the array). The length again is the same as X and Y. My comment mentions W and H meaning width and hight. Adusting these will change the width and height of each slider.

I have tried to experiment with the sliders chaning the grayscale, but I don't have enough experience with matplotlib, so I couldn't get it to work. Sorry!

D
Quote
#5
Hi DreamingInsanity, Thanks for your help. I'll post the second part of the problem on the GUI forum.
I couldn't get the sliders to position neatly by adjusting y (one of them overlaps the x-axis). If anyone can suggest how I can either move the heatmap up or make the window bigger vertically so I can move the sliders down, that would be a really big help Wall Big Grin
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  HX711&matplotlib problems olego 0 41 Jul-12-2019, 12:22 PM
Last Post: olego
  Matplotlib problem ift38375 0 77 Jul-02-2019, 02:55 PM
Last Post: ift38375
  Matplotlib contour no data coordinates b4rtt 1 162 Jun-18-2019, 09:36 AM
Last Post: b4rtt
  Matplotlib ImportError robertinoc 4 270 Jun-14-2019, 09:11 AM
Last Post: snippsat
  Matplotlib animation problem Potatoez 1 303 May-21-2019, 03:58 PM
Last Post: Potatoez
  Animation using matplotlib query JohnDoe 0 122 May-09-2019, 08:07 PM
Last Post: JohnDoe
  How do i get matplotlib event handling to work? jenya56 3 340 Apr-24-2019, 06:53 PM
Last Post: jenya56
  Matplotlib 3d voxels animation jasiekkm 0 166 Apr-07-2019, 07:44 AM
Last Post: jasiekkm
  Matplotlib is all messed up! 64humans 1 433 Mar-16-2019, 08:04 PM
Last Post: libervurto
  matplotlib annotate datapoints with corresponding dates nuncio 0 170 Feb-08-2019, 11:26 AM
Last Post: nuncio

Forum Jump:


Users browsing this thread: 1 Guest(s)