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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:35:50+00:00 2026-05-14T02:35:50+00:00

I’d like to display a colorbar representing an image’s raw values along side a

  • 0

I’d like to display a colorbar representing an image’s raw values along side a matplotlib imshow subplot which displays that image, normalized.

I’ve been able to draw the image and a colorbar successfully like this, but the colorbar min and max values represent the normalized (0,1) image instead of the raw (0,99) image.

f = plt.figure()
# create toy image
im = np.ones((100,100))
for x in range(100):
    im[x] = x
# create imshow subplot
ax = f.add_subplot(111)
result = ax.imshow(im / im.max())

# Create the colorbar
axc, kw = matplotlib.colorbar.make_axes(ax)
cb = matplotlib.colorbar.Colorbar(axc, result)

# Set the colorbar
result.colorbar = cb

If someone has a better mastery of the colorbar API, I’d love to hear from you.

Thanks!
Adam

  • 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-05-14T02:35:50+00:00Added an answer on May 14, 2026 at 2:35 am

    It looks like you passed the wrong object to the colorbar constructor.

    This should work:

    # make namespace explicit
    from matplotlib import pyplot as PLT
    
    cbar = fig.colorbar(result)
    

    The snippet above is based on the code in your answer; here’s a complete, stand-alone example:

    import numpy as NP
    from matplotlib import pyplot as PLT
    
    A = NP.random.random_integers(0, 10, 100).reshape(10, 10)
    fig = PLT.figure()
    ax1 = fig.add_subplot(111)
    
    cax = ax1.imshow(A, interpolation="nearest")
    
    # set the tickmarks *if* you want cutom (ie, arbitrary) tick labels:
    cbar = fig.colorbar(cax, ticks=[0, 5, 10])
    
    # note: 'ax' is not the same as the 'axis' instance created by calling 'add_subplot'
    # the latter instance i bound to the variable 'ax1' to avoid confusing the two
    cbar.ax.set_yticklabels(["lo", "med", "hi"])
    
    PLT.show()
    

    As i suggested in the comment above, i would choose a cleaner namespace that what you have–e.g., there are modules with the same name in both NumPy and Matplotlib.

    In particular, i would use this import statement to import Matplotlib’s “core” plotting functionality:

    from matplotlib import pyplot as PLT
    

    Of course, this does not get the entire matplotlib namespace (which is really the point of this import statement) though this is usually all that you’ll need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters

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.