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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:15:39+00:00 2026-06-18T04:15:39+00:00

I am plotting a histogram using plt.imshow(hist2d, norm = LogNorm(), cmap = gray) where

  • 0

I am plotting a histogram using

plt.imshow(hist2d, norm = LogNorm(), cmap = gray)

where hist2d is a matrix of histogram values. This works fine except for elements in hist2d that are zero. In particular, I obtain the following image

Histogram

but would like the white patches to be black.

Thank you!

  • 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-18T04:15:40+00:00Added an answer on June 18, 2026 at 4:15 am

    Here’s an alternative method that does not require you to muck with your data by setting a rgb value for bad pixels.

    import copy
    data = np.arange(25).reshape((5,5))
    my_cmap = copy.copy(matplotlib.cm.get_cmap('gray')) # copy the default cmap
    my_cmap.set_bad((0,0,0))
    plt.imshow(data, 
               norm=matplotlib.colors.LogNorm(), 
               interpolation='nearest', 
               cmap=my_cmap)
    

    The problem is that bins with 0 can not be properly log normalized so they are flagged as ‘bad’, which are mapped to differently. The default behavior is to not draw anything on those pixels. You can also specify what color to draw pixels that are over or under the limits of the color map (the default is to draw them as the highest/lowest color).

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

Sidebar

Related Questions

When plotting a sparsity matrix using spy in MATLAB, the text nz=x , where
I'm plotting planes in matlab using ezmesh. Everything goes fine until I attempt to
I am plotting some data series along with regression lines using this code: ggplot(dt1.melt,
I am plotting a heatmap in matplotlib using: plt.pcolor(rand(5,5)) how can I annotate the
I am having trouble plotting sorted values inside each facet using ggplot2. Here is
plotting module def plotGraph(X,Y): fignum = random.randint(0,sys.maxint) plt.figure(fignum) ### Plotting arrangements ### return fignum
When plotting color-maps using gnuplot, I usually use the following lines: ... set palette
I am plotting boxplots from this data: MY_LABEL MY_REAL MY_CATEGORY 1 [POS] .56 POS
I'm plotting data in Python using matplotlib. I am updating the data of the
I'm plotting some data curves with gnuplot, and they look like this: However, the

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.