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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:57:18+00:00 2026-05-27T11:57:18+00:00

I am trying to make a contour plot with the contour levels scaled by

  • 0

I am trying to make a contour plot with the contour levels scaled by the log of the values. However, the colorbar does not show enough values next to the colors. Here is a simple example.

import numpy as N
import matplotlib as M
import matplotlib.pyplot as PLT

# Set up a simple function to plot 
values = N.empty((10,10))
for xi in range(10):
    for yi in range(10):
        values[xi,yi] = N.exp(xi*yi/10. - 1)

levels = N.logspace(-1, 4, 10)
log_norm = M.colors.LogNorm() 
# Currently not used - linear scaling
linear_norm = M.colors.Normalize()

# Plot the function using the indices as the x and y axes
PLT.contourf(values, norm=log_norm, levels=levels)
PLT.colorbar()

If you switch log_norm for linear_norm in the contourf call, you’ll see that the colorbar does have values. Of course, using linear_norm means the colors are scaled linearly and the contours are not well distributed for this function.

I’m using python 2.7.2, enthought edition which comes with matplotlib, on Mac OS 10.7.

  • 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-27T11:57:19+00:00Added an answer on May 27, 2026 at 11:57 am

    Add a format to the call to PLT.colorbar:

    import numpy as N
    import matplotlib as M
    import matplotlib.pyplot as PLT
    
    # Set up a simple function to plot 
    x,y = N.meshgrid(range(10),range(10))
    values = N.exp(x*y/10. - 1)
    
    levels = N.logspace(-1, 4, 10)
    log_norm = M.colors.LogNorm() 
    # Currently not used - linear scaling
    linear_norm = M.colors.Normalize()
    # Plot the function using the indices as the x and y axes
    PLT.contourf(values, norm=log_norm, levels=levels)
    PLT.colorbar(format='%.2f')
    PLT.show()
    

    enter image description here

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

Sidebar

Related Questions

I'm trying to show a contour plot using matplotlib from a complex array. The
I am trying to make a contour plot of the following data using matplotlib
Trying to make a sliding panel where you can click next and back to
Trying to make a simple toggle menu, and I can't seem to hide/show the
Im trying make a menu with the next structure: -category 1 --category 1.1 ---category
Trying to make a setup for my application. However, I am having trouble getting
Trying to make a loop of MAC address values with: String macAddr = AA:BB:CC:DD:;
trying to make a template, but I have an error in gcc4 but not
I am trying make long screen to vertical direction. So, I need a screen
Trying to make a make generic select control that I can dynamically add elements

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.