1

Is there anyway to make a color a lot brighter in matplotlib?

I have the following color map:

 cmap = clr.LinearSegmentedColormap.from_list('red_yellow', 
                                         [(0,'#00001a'),
                                          (0.59,'#e60000'),
                                          (0.85,'#ff8000'),
                                          (0.97,'#ffcc00'),
                                          (1,'#ffff00')], N=600)

which looks like this:

enter image description here

My question:

Is there any way to make the yellow color in the last bracket of the colormap [given by this line: (1,'#ffff00')] look way brighter than it does now?

It's not really that I want the color to be 'lighter', it's more that I want it to stand out more, kind of like it is illuminated and 'glowing' hot. I want to keep the warmth of the yellow while making it look VERY bright.

I want it to really stand out, almost like it is shining. Is there any way to do this in matplotlib?

Thanks.

Community
  • 1
  • 1
fosho
  • 1,666
  • 6
  • 20
  • 28

1 Answers1

1

Easiest way i can think of is convert it to HSL, up the lightness, and then convert it back. If you're going to go down this route, i'd use the colorsys library - i have a load of examples where i use it, i'll have a look for one probably tomorrow if you still need it (or if someone else doesn't beat me to it).

Or, you could just pick a different colour - you want it to be whiter - it looks like you're going for black body colours - this library is good, though might be a bit overkill. Have a look at the simulation in here for a black hole - the colour is essentialyl white, but when you combine it properly with the other colours we're used to being associated as hot, it will look much brighter. Other than that though, i think adding bloom in matplotlib would be very complicated*.

*if you really wanted to, i guess you could do it with lots of transparent layers, but it would be hard since matplotlib is terrible for 3d stuff (it actually plots 3d objects as flat ones, there's no intersection - you need to do it yourself carefully, i have another answer about this elsewhere).

will
  • 10,260
  • 6
  • 46
  • 69
  • Hi Will, thanks for the answer. How much brighter will it make the color? – fosho Jul 02 '16 at 11:20
  • it depends how much you alter the colour by... Given that you're just using a list for the colours though, why not just pick one that looksthe appropriate level of brightness? Or, just pick the matplotlib colour map that does what you want? [you want "afmhot"](http://matplotlib.org/examples/color/colormaps_reference.html). – will Jul 02 '16 at 11:26
  • It's not really that I want the color to be 'lighter', it's more that I want it to stand out more, kind of like it is illuminated and 'glowing' hot. – fosho Jul 02 '16 at 11:33
  • Did you try afmhot? You could try a dark background too. – will Jul 02 '16 at 21:46
  • Sorry for bugging you here, but Docs still has no commenting. I like your touch with [the invisible bridge trick](http://stackoverflow.com/documentation/proposed/changes/49520), haven't seen that before. But I've had problems with [single surfaces](http://stackoverflow.com/questions/35099455/only-plot-part-of-a-3d-figure-using-matplotlib/35101731#35101731) (disconnected by NaNs) and [bar plots](http://stackoverflow.com/questions/35246780/is-it-possible-to-superimpose-3-d-bar-charts-in-matplotlib/35248519#35248519), etc. It seems to me that the trick is not universally applicable. Do you agree? – Andras Deak -- Слава Україні Jul 27 '16 at 21:50
  • The trick would be universally applicable, but it would take a lot more nastiness. You could filter out nans before you plot, and for a bar plot you could grab all the bars and concert them into a single surface. It would not be pleasant though. If you truly want 3d plotting, mayavi makes it much easier. – will Jul 28 '16 at 06:34
  • OK, thanks, just wanted to know what you think. I fully agree with mayavi instead; I'm only wondering about the phrasing of the docs page. It currently says "*This can however be fixed.*", maybe it should be softened to make it clear that this is only an option in a few cases. Please let me know when you've read this; I'll delete my off-topic comments:) – Andras Deak -- Слава Україні Jul 28 '16 at 10:03