I am trying to plot the values of a bitwise circular shift on 1 byte. I’d like to have a slider let me change the original input value. I’m using the slider example on the matplotlib site for reference, but for some reason even though I pass in 0-255 as my slider range when I run my script the range is always 0-7. I’m guessing that somehow the slider is getting locked to my maximum number of x values, but I don’t see how. How do I get the slider to let me pick the full 0-255 range?
Also, despite the min/max I’ve given the slider it inserts some padding for going below 0 at the front, and randomly draws a verticle line in the middle of my slider. How do I get rid of it? (also what is it for? The purpose isn’t obvious to me)
Picture of slider only going up to 7:

Code:
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
from numpy import uint8
from numpy import uint16
from numpy import uint32
from numpy import uint64
def sizeof(x):
return [uint8, uint16, uint32, uint64].index(x) + 1
def rot(x, i):
return type(x)((x >> i) | (x << (sizeof(type(x))*8 - i)))
def plotShifts(x):
origType = type(x)
maxval = type(x)(-1)
numrots = sizeof(type(x)) * 8
vals = [rot(x, i) for i in range(numrots)]
print vals
l, = plt.plot(range(numrots), vals, 'ro')
axcolor = 'lightgoldenrodyellow'
inputax = plt.axes([0.15, 0.05, 0.65, 0.03], axisbg=axcolor)
inputsl = Slider(inputax, 'Input', 0, maxval, valinit=0, valfmt="%d")
def update(x):
vals = [rot(origType(x), i) for i in range(numrots)]
l.set_ydata(vals)
plt.draw()
inputsl.on_changed(update)
plt.axis([-0.5, numrots-1 + 0.5, -2, maxval + 2])
plotShifts(uint8(1))
plt.show()
The problem is in the last line
plt.axis([-0.5, numrots-1 + 0.5, -2, maxval + 2])which is acting on the axes that holds the slider, not on the axis with the data.I would recommend using the OO interface to
matplotlibrather than thepyplotinterface for anything programmatic. Thepyplotinterface is good for interactive stuff, but it has a good deal of hidden state.You also need to return a reference to the
sliderobject due to the way call backs work.