Invert a histogram by emphasizing on the valleys

Hello! I have a regular histogram, where I have my peaks at a certain frequencies. However, i want to emphasize on the valleys in my histogram rather than on the peaks. How do I make it so? I want my new histogram to display the peaks as the spaces with the biggest valleys in the initial plot. Like invert it, in a sense?

7 Comments

Can you provide a picture or data? just to visulize what you're looking for.
Hi! So i kinda butchered the picture, but hopefully this will give you an idea of what i'm trying to do. Basically invert the histogram so the places that used to represent the valleys are now the peaks, and vice versa.
Would it be enough to zoom in the vertical direction such that the all histogram-ampltudes above some level disappears from the view and only the variations around your valeys remain - Turning things upside-down might be confusing to the "instant interpretation" of your plot. Perhaps attach an image with your histogram?
Perhaps something as simple as:
set(gca,'YDir','reverse')
Thank you very much; however, this is not what I was looking for.
@kathsb, what picture? I'm not seeing any picture that you uploaded or butchered. Did you remove it?
And do you just want to somehow invert the bar chart, or do you actually want to change the original data from which it came?
And why? What is the use case? It seems like the result could be misleading. Why would you want to do that?
You already accepted an answer below, so we assume you've already solved the problem so not sure why you're continuing to post.
@Image Analyst I have removed the picture after i accepted the answer due to personal reasons. The reason I'm looking for this kind of interpretation is just purely for scientific analysis and the result wouldn't be misleading in this particular case. Now regarding my last comment, I was simply just trying to be polite and thank the contributor for their help.

Sign in to comment.

 Accepted Answer

One way to do that probably is by subtracting the rate in each bin from the maximum rate. Below is an example with normal distribution. I'm not sure though if interpreting this result is very meaningful.
clc, clear
x = randn(1, 1000);
h1 = histcounts(x);
h2 = max(h1)-h1;
bar(h1, 'FaceAlpha', 0.5), hold on, bar(h2, 'r', 'FaceAlpha', 0.5);

2 Comments

Thank you very much for your help!
Instead of using bar you could use the output from histcounts as the BinEdges and BinCounts in a call to histogram.
x = randn(1, 1e5);
[counts, edges] = histcounts(x);
histogram('BinEdges', edges, 'BinCounts', max(counts)-counts)

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2021a

Asked:

on 20 Aug 2021

Commented:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!