Python Forum
[matplotlib]Heatmap with Sliders
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[matplotlib]Heatmap with Sliders
#1
Wondered if anyone can help. I'm a total newbie to python and banging my head off the wall on this one.
I have 2 sliders and a heatmap.
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 MOD64 to limit the grayscale values

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()
Reply
#2
No need for anyone to reply as I think I know how to solve this now. I'll post code here once done so i'll leave open for now. Thanks everyone.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020