3

here is my problem. I have some data I binned to obtain a "digitalised" pdf, and that's fine. Now, I wanted to find a way to indicate different confidence intervals by coloring the bin groups differently. In particular, starting with the bin containing the highest count I wanted to find and colour, say red, all the highest bins whose area sum to less than say .6. Then, always picking new bins by decreasing counts, i want to colour the bins who increase my red area to .8 in orange. I was considering using numpy to get bins and counts, sort them into 3 series (red, orange and original colour) and plot them with pyplot's bar. Hope you can point out a faster way, thanks!

1
  • Nope, I was just considering doing that, still I'm thinking about possible more efficient ways. I'd like to avoid sorting my values into 3 different lists :S Commented Jun 2, 2011 at 10:22

1 Answer 1

6

If I understand your question correctly, I think the code below will do what you are suggesting. It seems a little different than the approach you were considering, and I'm not sure it is more efficient. Regardless, it usually helps to see the way someone else would do something. It assumes an already generated pdf (histogram) with a bins represented by the varialble "bins" and bin width represented by the variable "binwidth".

gray = (.5,.5,.5)
orange = (1.0, 0.647, 0.0)
red = (1.0, 0.0, 0.0)

clrs = [gray for xx in bins]

idxs = pdf.argsort()
idxs = idxs[::-1]
oranges = idxs[(cumsum(pdf[idxs])*binwidth < 0.8).nonzero()]
reds = idxs[(cumsum(pdf[idxs])*binwidth < 0.6).nonzero()]

for idx in oranges:
    clrs[idx] = orange

for idx in reds:
    clrs[idx] = red

bar(left=bins,height=pdf,width=binwidth,color=clrs)

Here is a view of the result that I get along with the associated PDF and CDF

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.