Wikipedia:Reference desk/Archives/Computing/2016 March 23#Color Palette for Maps

{{#ifeq:{{PAGENAME}}|Special:Undelete| |{{#if:|

}} {{#ifeq:{{NAMESPACE}}|Wikipedia|{{#switch:{{NAMESPACE}}|= |
}}|{{error:not substituted|Archive header}}
}}}} {{#if:|
}}
width = "100%"
colspan="3" align="center" | Computing desk
width="20%" align="left" | < March 22

! width="25%" align="center"|<< Feb | March | Apr >>

! width="20%" align="right" |{{#ifexist:Wikipedia:Reference desk/Archives/Computing/2016 March 24|March 24|Current desk}} >

align=center width=95% style="background: #FFFFFF; border: 1px solid #003EBA;" cellpadding="8" cellspacing="0"
style="background: #5D7CBA; text-align: center; font-family:Arial; color:#FFFFFF;" | Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is {{#ifexist:Wikipedia:Reference desk/Archives/Computing/2016 April 2|an archive page|a transcluded archive page}}. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.

__TOC__

= March 23 =

Color Palette for Maps

I asked for help on generating "consecutive" colors for a map before here[https://en.wikipedia.org/wiki/Wikipedia:Reference_desk/Archives/Computing/2016_March_4#Calculating_11_.22consecutive.22_colours] and got some really helpful responses. I just want to thank you guys again.

Here's the map I got[http://i.imgur.com/uhmdlP5.png], a map of the 50 US states colored according to their population. While California and Texas and the lowest population states looks "correct", everything looks looks off. For example, Florida looks far too light compared to California; just by looking at this map you won't get the impression that Florida has half the population of California. Likewise, Pennsylvania doesn't look like one-third the population of California. Anything between 10 million and 20 million feels much lighter than it should be.

Seems like (at least to my eyes), naively using a linearly progressing color scale will not be able to produce the right psychological results on the viewer. How do professional map makers do this? What kind of color scales do they use?

Here's the code I used to generate the 50 shades 40 shades of green (credits to Finlay McWalter):

  1. !/usr/bin/python3

import colorsys

steps = 40

hue = 0.328

satInitial = 1

satFinal = 0

def frange11(x, y):

m = steps - 1

return ((m-i)/m*x + i/m*y for i in range(steps))

for v, sat in zip(frange11(0.5, 1.0), frange11(satInitial, satFinal)):

r,g,b = map(lambda x: round(x*255),

colorsys.hsv_to_rgb(hue, sat , v))

color = '#{:02x}{:02x}{:02x}'.format(r,g,b)

print ('

 
'.format(r,g,b))

The output color palette definitely looks "correct", but it produces the "wrong" effect when applied to a map.

{{hat|colours}}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

{{hab}}

Johnson&Johnson&Son (talk) 14:24, 23 March 2016 (UTC)

:I tried the website[http://gka.github.io/palettes/#colors=darkgreen,white|steps=40|bez=1|coL=1] BenRG referenced too, and it basically uses the same technique as above and gives out a similar result. Johnson&Johnson&Son (talk) 14:29, 23 March 2016 (UTC)

:A few comments: 1) I don't know, that map looks decent to me, and I might have said FL had half the pop of CA. 2)Usually maps of states don't use single-hue color maps, that's usually more for things like population density, and sampled at much higher resolution. 3)There are many famous and widely used colormaps. "Jet" was developed by JPL and is used in lots of science publication, but here [https://jakevdp.github.io/blog/2014/10/16/how-bad-is-your-colormap/] is a contrarian view that strongly critiques Jet, and argues that cubehelix [https://www.mrao.cam.ac.uk/~dag/CUBEHELIX/] is always better than Jet, though it might not always be the best. If you're stuck on single-hue, you might find more pleasing results with a log or exp mapping to saturation rather than linear. But I think for a map like this the pros use multi-hue maps and include colorbar with labeled values. SemanticMantis (talk) 14:36, 23 March 2016 (UTC)

::Thanks. How do I implement an exponentially decreasing saturation in Python? I'm really new at this.

::Should I go with exponential saturation + linear value or do I need exponential saturation + exponential value as well? Johnson&Johnson&Son (talk) 05:44, 24 March 2016 (UTC)

:A lot of the problem of doing a simple linear interpolation between two colors is that our eyes are non-linear systems. Halving the numerical value of a color doesn't produce a color halfway between that color and black. Sure, it produces half the brightness on the screen of the monitor or the ink density on the paper - but our eyes don't perceive it as half as bright. You should (at a minimum) gamma-correct the resulting image. SteveBaker (talk) 15:32, 23 March 2016 (UTC)

::Ah yes, that's the term I was forgetting: gamma correction. SemanticMantis (talk) 17:56, 23 March 2016 (UTC)

::sRGB is already gamma-corrected. I don't think there's any gamma you could apply here that would make this more perceptually uniform. It would help to work in a more perceptually uniform space like Lab or Luv and then transform to sRGB, which is what the Javascript colormap generator that I suggested does. -- BenRG (talk) 19:28, 23 March 2016 (UTC)

:It's not related to your question, but that frange function is awful, despite being from a highest-rated answer on StackExchange. In fact, it's giving you 41 colors instead of 40 because of roundoff error. I took the liberty of fixing it. If you actually wanted 41 colors, change steps to 41. Also, the right way to convert from 0..1 to 0..255 is round(x*255), not int(x*256). -- BenRG (talk) 19:28, 23 March 2016 (UTC)

  • By the way: Why color by raw population rather than by population density? —Tamfang (talk) 08:21, 25 March 2016 (UTC)

::As at least two people pointed out, this type of cartography (choropleth mapping) should never be used for absolute data like populations for the reason the Original Poster mentioned: different units' areas introduce perceived distortions. Choropleth maps should only be used for nominal data (like the party of an electoral result), ratio data (like temperatures or population densities), or ordinal data (like presidential approval ratings). Consider a map of the US showing the number of Nobel prize winners per state. Imagine that Alaska and Rhode Island have the same number. It will look bigger in Alaska, which would be wrong. If you need to depict absolute data, use proportional symbols or random dots or another method.Hayttom (talk) 15:10, 26 March 2016 (UTC)

Is there some equipament like this?

Its there some equipament like this?

People plug their (turned on) media players on the equipaments (not just one person but more than one), than then you plug this equipament on a speaker or car.

The player will play the audio coming form the first media player and after some minutes will play only the audio coming from the second, and then the audio coming from the third.....

This way people with different music tastes can share the same speaker or car speaker. By changing after X minutes, this also means the equimapent will not be biased toward long songs.201.79.54.91 (talk) 19:58, 23 March 2016 (UTC)

:I don't think such a device exists, and if it did the result would be horrible to listen to. Imagine 3 people, one listens mainly to drum and bass, the other one likes hiphop and the third one likes to listen to metal. You can chose to play one of these music styles all night, which would make one of them happy. The ideal solution is to find a compromise, for example reggae, that all three can enjoy (even though it isn't their favorite type of music). But listening to partial songs of those different genres would make all three unhappy. The Quixotic Potato (talk) 21:03, 23 March 2016 (UTC)

::Also, all your media players would have to be playing the whole time while only one would be actually heard, which seems terribly inefficient. At many parties I've been to we just take turns connection our phones to the bluetooth speaker and playing a song. Yes you have the problem of people not being "fair" and playing long songs or unpopular songs, but people who play long unpopular songs quickly get voted off the speaker by the majority and people who play popular songs don't get voted off, so it it ends up working mostly, as long as you have roughly similar tastes in music. I indeed like some full on death metal but I wouldn't subject a "party" to it, so I chose electronica and other more "easy listening" music that most people wont' hate. Vespine (talk) 21:38, 23 March 2016 (UTC)

:::"Also, all your media players would have to be playing the whole time while only one would be actually heard, which seems terribly inefficient." The point of this is that the song is not biased toward long songs, if on this system you played just one song and then played another ipod song, this system would be biased toward people that likes long songs, so the system would play a long song like an ambient song and then play a small song like a grindcore or hardcore song. Also if instead of playing one song, the system played songs for X minutes before changing to another ipod that would then be turned on just to start to play the songs of his round,this would save energy, but on long songs you would always play the first X minutes of a long song and would never listen to the rest of the song. Because of those 2 problems, I asked for this specific device, this device (change what "ipod" is playing after X seconds) is easier to be created than one that somehow detects when a song ends, or one that can actually make the ipod select a new song when its his turn.201.79.65.77 (talk) 12:53, 24 March 2016 (UTC)

:I doubt anyone would make something like this - it would drive consumers up the wall to have one song cut off partway through, dropping you into the middle of another song, also partway through, in a different musical style. It makes more sense to put the 'jump' between songs - but for that to happen, this hypothetical gadget would need to know when a song ended - and it would have to be able to tell these various MP3 players to start playing at the beginning of a song. That would imply that the central gadget would have to be able to control every other kind of MP3 player remotely - and that's impossible because there are too many players already out there that don't have that capability.

:The BEST way to do what you want would be to treat each MP3 player as a 'memory stick' (most of them can do that) - to plug them into an MP3 player with many USB connections and to give it a "random-play" setting that fairly picked tracks from each of the USB connections. However, I still doubt that there is such a device.

:It would be fairly simple to build one using a USB hub and a tiny computer like a RaspberryPi. With a very little amount of 'shell programming' skill, I'm sure software could be built to pick the next memory device from a list, select a random track from that device, then feed it into a standard MP3 replay software package. But you'd need to be fairly desperate to have such a device to make it worthwhile. I don't think many people would want to buy one. Honestly - just have everyone wear headphones and listen to what the heck they want! SteveBaker (talk) 13:25, 24 March 2016 (UTC)

::"Honestly - just have everyone wear headphones and listen to what the heck they want! " Not in parties, cars, at work...201.79.65.77 (talk) 13:58, 24 March 2016 (UTC)

:::Silent disco. When I am working I am usually wearing headphones. The Quixotic Potato (talk) 19:38, 28 March 2016 (UTC)