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

  • Home
  • SEARCH
  • 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 6026373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:26:09+00:00 2026-05-23T04:26:09+00:00

I have a 2D numpy array that I want to plot in a colorbar.

  • 0

I have a 2D numpy array that I want to plot in a colorbar. I am having trouble changing the axis so that they display my dataset. The vertical axis goes ‘down’ from 0 to 100, whereas I want it to go ‘up’ from 0.0 to 0.1. So I need to do two things:

  • Flip the array using np.flipud() and then ‘flip’ the axis as well
  • Change the labels to go from 0.0 to 0.1, instead of 0 to 100

Here is an example of what my colorbar plot currently looks like:
Example of Colorbar plot

And here is the code:

data = np.load('scorr.npy')
(x,y) = np.unravel_index(data.argmax(), data.shape)
max=data[x][y]

fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.imshow(data, interpolation='nearest')
cbar = fig.colorbar(cax, ticks=[-max, 0, max])
cbar.ax.set_yticklabels([str(-max), '0', str(max)])
plt.show()

Does anybody have any suggestions? Thanks in advance!

  • 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-23T04:26:10+00:00Added an answer on May 23, 2026 at 4:26 am

    You want to look at the imshow options “origin” and “extent”, I think.

    import matplotlib.pyplot as plt
    import numpy as np
    
    x,y = np.mgrid[-2:2:0.1, -2:2:0.1]
    data = np.sin(x)*(y+1.05**(x*np.floor(y))) + 1/(abs(x-y)+0.01)*0.03
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ticks_at = [-abs(data).max(), 0, abs(data).max()]
    cax = ax.imshow(data, interpolation='nearest', 
                    origin='lower', extent=[0.0, 0.1, 0.0, 0.1],
                    vmin=ticks_at[0], vmax=ticks_at[-1])
    cbar = fig.colorbar(cax,ticks=ticks_at,format='%1.2g')
    fig.savefig('out.png')
    

    extent and origin

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

Sidebar

Related Questions

I have a numpy array of pixel data that I want to draw at
I want to get the index of the min value of a numpy array
Suppose I have a numpy array x = [5, 2, 3, 1, 4, 5]
I have a 2D numpy array of shape (N,2) which is holding N points
Let's say I have a 2D Numpy array: >>> a = np.random.random((4,6)) and I
I have a numpy.array of 640x480 images, each of which is 630 images long.
I have a multidimensional numpy array, and I need to iterate across a given
How does one add rows to a numpy array? I have an array A:
I'm trying to get a better grip on numpy arrays, so I have a
I have an application that receives a pointer to JPEG data from a camera

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.