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 8743001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:36:01+00:00 2026-06-13T11:36:01+00:00

I am trying to plot the values of a bitwise circular shift on 1

  • 0

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:
enter image description here

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()
  • 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-06-13T11:36:02+00:00Added an answer on June 13, 2026 at 11:36 am

    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 matplotlib rather than the pyplot interface for anything programmatic. The pyplot interface is good for interactive stuff, but it has a good deal of hidden state.

    You also need to return a reference to the slider object due to the way call backs work.

    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 2 ** [uint8, uint16, uint32, uint64].index(x)
    
    def rot(x, i):
        return type(x)((x >> i) | (x << (sizeof(type(x))*8 - i))) 
    
    def plotShifts(x):
        fig = plt.figure() # make a new figure
        ax = fig.add_axes([0.15, 0.2, 0.65, 0.7]) # add data axes
        origType = type(x)
        maxval = type(x)(-1)
    
        numrots = sizeof(type(x)) * 8
        vals = [rot(x, type(x)(i)) for i in range(numrots)]
    
        print vals
        print maxval
        l, = ax.plot(range(numrots), vals, 'ro') # plot to data axes
    
        axcolor = 'lightgoldenrodyellow'
        inputax = fig.add_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), origType(i)) for i in range(numrots)]
            l.set_ydata(vals)
            plt.draw()
        inputsl.on_changed(update)
    
        ax.set_ylim([-2,maxval +2]) # set ylim on data axes
        ax.set_xlim([-.5,numrots-1+.05]) # set xlim on data axes
    
    
        return inputsl
    
    sldr = plotShifts(uint8(1))
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to plot values using matplotlib and i have several different classes
I'm trying to plot values as a function of the date (only hh:mm:ss, without
I am trying to give float point into core-plot y axis value, it is
I am trying to plot a graph using gnuplot. I have six text files.
Is the use of NSDateformatter required when I'm trying to plot the epoch values
I'm trying to plot a graph with a set of x-values and y-values in
I'm trying do define an interface in which I want to plot some values
I have been trying to plot these on a scatter chart using google api.
I'm trying to create a plot where color represents the combination of several values.
I am trying to use the plot function in R. I would like to

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.