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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:12:18+00:00 2026-06-17T09:12:18+00:00

I am trying to create a filled contour plot in matplotlib using colormap. I

  • 0

I am trying to create a filled contour plot in matplotlib using colormap.
I want to change color of the specified value.

For example,

levs = [-3,-1,1,3]
plt.contourf(x,y,z,levs,cmap=cm.jet,extend='both')

I hope the color between -1 and 1 to white keeping the other colors default colormap.

Sorry for my bad english.
Any help would be appreciated.

  • 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-17T09:12:19+00:00Added an answer on June 17, 2026 at 9:12 am

    I would just overplot the same contour plot, but then just with levels between -1 and 1, with color white.

    For example:

    from matplotlib import pyplot as plt
    from matplotlib import cm
    import numpy as np
    
    x, y = np.mgrid[-100:100,-100:100]
    x /= 10.
    y /= 10.
    r = np.sqrt(x*x+y*y)
    z = 10*np.sin(r)/(r+0.01)
    levels = [-4, -3, -2, -1, 1, 2, 3, 4]
    plt.contourf(x, y, z, levels=levels, extend='both', cmap=cm.jet)
    levels = [-1, 1]
    plt.contourf(x, y, z, levels=levels, colors='w')
    plt.savefig('contours.png')
    

    Update

    In case you want more control, set the colors keyword in contourf to a tuple of matplotlib colors, with the same number of elements as you have levels (minus 1: the colors correspond to the intervals between your level boundaries). Then, you don’t need to overplot a separate contour, and your colorbar is also correct:

    # same as before
    levels = [-4, -3, -2, -1, 1, 2, 3, 4]
    plt.contourf(x, y, z, levels=levels, extend='both', colors=('#ff0000', '#ff9900', '#999900', 'w', '#009999', '#0099ff', '#0000ff'))
    plt.savefig('contours.png')
    

    Even nicer perhaps is to define your own colormap, but then you’ll likely run into the issue that you have to match your colormap exactly with your contour levels. Which is the why, conveniently, colors keyword exists.

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

Sidebar

Related Questions

I am trying to create a filled contour plot in matplotlib (Win7, 1.1.0). I
I'm trying to plot a box within a filled.contour plot, but unfortunately, when I
I am trying to create a table layout filled with lots of bits of
I am trying to create two select lists both filled with the same times.
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
I am trying to create one rectangle filled with Horizontal or Vertical lines. The
i'm trying to create a registration system using jsp, beans and servlets. Registration process
I am trying to create a multi step form using model classes: my view:
Using extension syntax I'm trying to create a left-join using LINQ on two lists

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.