1

I have the following MWE

dat = [1,7,3,6,9,4]
plt.bar(range(len(dat)), dat, color='#1C5B26')
plt.savefig(path/tofile.pdf)

When I run this, then inspect the pdf, the hex value of the bars can be very far from what I specified. I would like the plot to be exactly the color I have specified, but I can even visually see that it is not close the the given hex value.

Any reasons this is happening/workarounds?

EDIT: Here is what I get when inspect. For the given hex value above I should get (28,91,38). I know its a small difference, but I thought the problem was worse when I was using a different "display in ..." option. sRGB is the option that I found gave me the best match, but still not perfect. enter image description here

2
  • I can't reproduce this issue. I created a figure using your code, then extracted the color from a pdf and it was exactly the same as what I specified in the script. Perhaps your pdf viewer has a different color profile set? Maybe you could show an example of your output to illustrate the issue. Commented Aug 14, 2017 at 15:41
  • @tom I was inspecting with a different option that led me to believe the difference was much larger, but even with sRGB there is still a small, albeit very small, difference. Commented Aug 14, 2017 at 16:48

1 Answer 1

1

I would want to comment this but I can't (<50 rep).

Going by the first answer from Named colors in matplotlib matplotlib is using a dict for it's colours.
He also links every available one. Using this dictionary for colors is the reason why you can't really choose whatever color you want.

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

2 Comments

Why would they not allow for arbitrary hex code? and do you know of any workarounds? I don't really want to search for the one thats the closest.
That answer only shows which named colors are available. Any RGB color can be specified (for example using a hex code), even if it doesn't have a name in that dict

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.