Python Forum
[matplotlib]Heatmap with Sliders - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [matplotlib]Heatmap with Sliders (/thread-18459.html)



[matplotlib]Heatmap with Sliders - punksnotdead - May-18-2019

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()



RE: [matplotlib]Heatmap with Sliders - punksnotdead - May-19-2019

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.