How to choose better colors for your data visualizations
With Python libraries such as matplotlib, seaborn, bokeh, plotly, altair, hvplot etc. it is easier than ever to create nice and colorful charts to visualize your data. Many people never change the basic configuration of the libraries because they do not know better (or worse: they do not care). This is why almost all charts look the same. Colors are an important tool to quickly transfer the message of your charts to the viewer. In order to make it easy for the people to understand your charts and your data, it is important to think about how to use colors in data visualization (usually the standard colors are not the colors that should be used!). Therefore, this talk will teach you some basics of color theory and help you to get started with using better colors in your charts.
This session took place in track PyData and was classified suitable for none domain / basic python by the speaker.
Transcript (auto)
Auto-generated from the recording utilizing Open-Source AI. Speaker labels (Speaker 1, Speaker 2) reflect diarization, not identity. Timestamps refer to the recording.
Speaker 1 [00:02]
Yeah. Hello, everybody. I'm really glad many people are excited about colors. So it's not only me. So just like to give you a short introduction of the idea of that talk. Like this year in spring, I went to the Hannover Fair, like the former CeBIT. And like all the companies are there having their cool dashboards, and they all looked horrible. And I was like, yeah, maybe somebody should tell them what they're doing wrong. So I came up with that idea for a talk. So I'm Daniel. I work in a small consultant company called Ancud IT. And I'm also, as you see with the color of my t-shirt, one of the organizers of PyData Berlin. So I'm really happy to have that many people here, and I hope we have some really cool days here. So I don't have that much time. So just to give a short introduction, I want to talk a little bit about color theory, the history some important people where you probably know most of them um i will talk a little bit about like color wheels so like it will be pretty hopefully a lot of the slides so it will be something pleasing to watch um i will talk a little bit about color models and um then give you some like psychology background and give you some like ideas on the road so like it's not that easy to choose good colors in general so i just want to like give you some ideas where to get started and like what really to avoid and i will end with some do's and don'ts to give get you like some ideas um what to do um so like first of all like to get started like i want all of you to think about like what is a color and to like try to describe the color for example green without examples of objects that are green and then you will maybe realize it's quite difficult to describe what green is if you don't can come up with examples and that's because like color is a really abstract concept in general so um yeah like if you think about back in school you probably know those charts about like human cone cells and how we as a human see colors um and that were like with just like wavelengths um and we have those three different cone cells for colors for like short medium and long um wavelengths and this is kind of how we as a human see colors and um this just like a short recap to get you an idea um this dashed line r is like a different cone cell which is only there for like darkness but not for color um but yeah like this is kind of like how it works in human brain and like we'll see some of those references later um and just now to be aware of like the connection of red and um and green is quite important later on so um to get started like what what is color theory like why is it quite a cool topic in my opinion it's like first of all it's a science and it's an art so it's kind of something like changing like it's something like a personal preference and taste so it makes it quite exciting there's not always like a right or wrong it's always something to to negotiate um it's a lot about like human perception like not everybody sees the same like this is also quite interesting in that field and we'll talk about it later a little bit about psychology um and the field is also about like color mixing where you see the connection to art like to mix colors together for painting for example it's about communication and also like color theory also describes method to replicate colors for example in different settings if you think about like printing a page it should look like the way it looks on your computer it's like you use color theory and all that all the time so like to start really back in the days like to just give you like some short introduction of like really important people in that field um the first one being uh aristoteles who was a greek philosopher and he wrote a book like basically the first known book about color called uh the coloribus which is which just means like on colors and um his concept of colors where that like all colors come from like white lightness um and dark um something like black color um which is quite good in a way of like we understand light now to the like light like white light is basically the full spectrum um and like you see a lot of people connect colors to something like um like they they can like see and um he used the four elements water air earth and fire to connect that to the colors so like he created his like first um basic color palette with like some different colors and yeah like if we go way later um probably nobody heard of like leon alberti who was like a quite famous italian architect um and now you think like yeah like an architect what does he have to do what colors um and he was doing a lot of like theoretical work in general and he wrote a book called the pictura which means on painting so he wrote like a guideline book for painting and it was a lot about perspective composition and colors um so he did not really like he was also a painter a little bit but didn't really get that successful so i guess he was not that good um but he defined that like black and white are not colors which is also quite interesting in a way that we see it now um and who made like big use of all the stuff he was writing in that book but like not really able to to like practice was oh first of all yeah he came up in that book with color mixing um so it was also like the first guy ever to like mix colors together in a book to like show how you can like create new colors with mixing colors together and um yeah like what i said before like you probably all know like da vinci and he really used all the theory in that book from alberti and used that for like creating his paintings for like many beliefs like are like the best paintings ever created by by humankind and um yeah like he used all that concept of colors and perspective and composition in his book so like he really like made practice out of the the concepts that alberti was doing and then yeah i guess isaac newton is like another guy who was really influential and like maybe the most influential scientist ever um and yeah you probably all know like his prism experiment um like like worst of all from the pink pink floyd cover on the left so i don't know how many of you remember that the original experiment had two prisms um so the last one where like white light passes through the prism and um it breaks into the whole spectrum of colors so like which is basically the pink floyd cover um but then in his experiment he also had a second prism where um only one of those colors was going through and he needed that to conclude that the prism does not alter or like change the color that goes through it it will just um um yeah like spread the white light into all the all the possible colors so like he needed that second second prison um as well and what he did then like which is like you know middle line with all those colors was he was the first guy to like come up with a color wheel um and like we'll see a couple of those now like i created the right one just for you to show because it's only in black and white and what is quite interesting here is like the number of colors that you choose on your color wheel is quite arbitrary like it just depends on like your personal preference or like what do you see um and what's quite interesting here is like before we are seeing like colors that were mapped to the four elements of the earth he mapped colors to musical intervals it's like to cd and like all of those which you can kind of see on the on the on the left here so that's also like a quite interesting connection in my opinion to like again combine kind of science and art into one field um then like we have johann schiffermüller who was an australian naturalist and he was the first guy to come up with this continuous color wheel so he combined all those colors into something like more continuous like the way we use it now um he came up with those like 12 colors like if you can read german you can maybe see that um and also what he was working on was like in addition to that picture that you see here he described a table with 81 shades of the color um we'll get soon to like what a shade is like by definition um but it gets quite interesting and here you see a real big connection to um to art and painting and moses harris was like another guy like an english guy who wrote a book that took him like quite a while like seven years and in that book he um he talked a lot about like color mixing also like quite the like artistic mindset um and like what i want to point out like i don't know how many of you have seen that picture which is quite famous um if you if you look in the middle you just have like three um triangles of blue yellow and just like reddish color um which were like his main colors that he used and if you check in the middle where all those colors overlap it creates some kind of shade of black so like we'll see that later in some different color models so like he was like the first guy to come up with like that idea um and like his idea is just to help artists to create colors for their painting but like we still use some of that stuff now then some guy you probably did not expect here it's like i don't know how many of you are german but like you probably all know goethe from like being a writer like really successful um in addition to that he was also like a statesman like he worked in politics uh he was a scientist as well and an artist and um he wrote a really important book called the theory of colors which was a lot about the human color perception um and he was also like a big painter like he was painting a lot of pictures that are quite good um which i guess many people really don't know so he created this like six color color wheel that you see here um in that book um and there's like a few things that are quite special here so first of all he was the first guy who recognized how important the magenta is and if you think about printing you still have like magenta print so he was the first guy who really understand the importance of that color um and like it's quite difficult to read like even if you read german but um in that color wheel he put in some attributes to colors so like he gave them some kind of like feeling uh what they what they say so in that example like he said yellow is um yellow is good and the green is useful and he says like violets are necessary so it's quite like you know random like his personal taste but um it's quite interesting if you think about like color psychology and what colors do um and he also came up with a concept of warm colors and cool colors we'll see that later again but i think that's quite cool so maybe he combined his like poetic mindset with colors and like created those those combinations um in an earlier study he also had a color wheel where he had some like occupation and character traits that he mapped to colors so like melancholic being like reddish colors for example um so i guess quite quite interesting in in that way and um Yeah, like another German guy, like Philipp Runge, he was like a penpal with Goethe. So they both worked on colors in a way. And he was the first guy who put like a third dimension into those color wheels. So like now we don't have a color wheel anymore. We have this color sphere. And on the top two, you see the two poles of it. So like he had three main colors, which were like yellow, red, and blue. and then on the top of the of the pole um you see like the white the white pole and on the on the right here you see uh black so um the two bottom pictures here just like if you cut that that like ball horizontally or vertically and this just creates like way more um ideas what you can do with colors and like create like many new many new shades so like who took that on the next level was Albert Mansell who was an American painter and teacher of art and what he developed is basically still the de facto standard in America so he took the ideas and really made them into scientific and came up with some concept and he defined three dimensions which you can see here we'll see those terms later again in more detail just to give you an idea of the color system that he he created quite important it's like this ring of colors where you see five main colors like blue and green and then you have five colors in between like this like blue green and green yellow that you see like on this like ring around it which he defined as being the u and then like you see from the top to the bottom just like grayish colors from black to gray to white and then if you go from inside the cube to the outside there's a value called chroma which is something like the like color strength like how strong that color is so like we'll talk about those like terms later but like this is just something really uh important to like define colors when we talk about color models so um if we go back a little bit more to the like artistic side like i don't know how many of you heard about bauhaus well like it's a quite special year right now for like a hundred year anniversary um so if you're longer in berlin they're cool museums to check out and like Bauhaus is mainly about architecture design but also about colors and like I will just focus on colors here so Johannes Itten was the Swiss artist and like he was a teacher in this like Bauhaus school and he wrote a book called the art of color where he created this kind of color wheel here so he was the first guy to talk about primary secondary and tertiary colors that you see here being like the three main colors in the middle those like triangular shaped things like red blue and yellow and if you mix two primary colors you get a secondary color and then the like tertiary colors mixed with like primary and secondary colors so he defined those concepts that i guess like still many people use and you often like read and hear about in that in that field yeah one of his students was joseph albers who's like a german artist and he later was also teaching in the bauhaus school and he wrote a book that's called and the interaction of color where he was just playing around with different colors and the effect if you put them next to each other um and like the first like print of that book was quite limited and they had like 150 like colored silk plates in it to to play around on your own so that was quite quite something new and i guess that book is now available as an ipad app if you want to play around with that um but mainly that book was talking about the relativity of color which like some color looks different like those two brownish rectangles here have the same color they just look different like not that much here but like much more on my my computer which is like perfectly on the field um yeah and like what he is most famous for is his like art series called the homage to the squares like i don't know how many museums you went to like maybe you've seen some of those where he just puts in like nested squares together with like different colors and you create some like really cool chromatic interaction with that and I guess like now this is kind of the question like is this art or is this science so I guess like this is like always this really interesting like connection to it and like those pieces were sold for like one to two million dollars so I guess that's quite good for an artist like maybe not science in that way but it definitely has some scientific value so yeah to like really make it quick like just to talk quickly about some definitions that like you often see in that field so you get a better idea like after today what people are talking about if they use some terms i just try to focus on the really important ones here so um if you're like tint tone and shade um this is quite an easy concept in general so like if you take a pure color like blue on the right and you mix pure white to it it's called tint if you mix pure black into it it's a shade and if you put in any shade of gray it's it is a tone so it's just like three terms that i guess are just used quite often interchangeably but like they just define something really really different um then we've seen you already like the ring on the mansell color model that we have seen so you is basically just a pure color um and the special part of you is that it's like specified as an angle so you have at like zero and 360 degrees you have red at 120 you have green and at 240 you have a blue but you can specify any pure color here on this like dimension and i guess like many people know like saturation which is just some like um like color intensity so on the left you can either mix white black or some kind of gray into it so on the left you will have like some shade of that and then like you go more into the pure color so like on the right you have like 100 100 of the pure color that we have seen on the u dimension um and then what's getting a little bit more tricky what you've seen before like the chroma um it's kind of like similar to like saturation and all those concepts are kind of related to each other um so that makes it a little bit difficult in my opinion to understand so when when we talk about chroma we we talk about the perceived strength of a color so what you see here maybe is like on the left we have like 100 white on the right we have 100 the color or black and then in the middle we have those shades of color or shades of gray and they all have the same lightness like this is a really important part here like you create some like lightness into into that dimension and yeah just to finish that up with something like a little bit more complex on the chart but like really easy to understand it's like there are two concepts called lightness and value which are really similar and like almost the same so i guess really important here is to understand like you have two charts here we have two colors like cyan and red next to each other which are like 180 degrees or like zero degrees in hue and then on the columns we see saturation from one to zero and then from zero to one again for the two colors and then what what i want to show you here is basically just like if you go the rows up and down which is like on the left we see lightness and on the right we see value so if you if you just want to try to like find the pure color you will see 50 of lightness is the pure color and 100 of lightness is just white light like makes sense on that in that way um value on the other side just like skips that into half so like on 100 of value you get the full pure color so whatever you have like 50 value that's the same as 100 of lightness so like they all like are together and like different systems like different color models use like different of those concepts so yeah if you talk about color models i guess you all know rgb and cmyk so just to give you like a really like short idea like rgb and cmyk being like color models like of a kind of different kind and the color model is always some kind of like abstract mathematical model and we have additive color models that you see on the on the left so you start with like darkness like black and then you add light colors to it to create like new colors and this is basically what you see everywhere on like your phone your tv your computer screen if you have like a black surface and you put colors on top of it and on the right like a subtractive color model is just the opposite you start with lightness like a like blank sheet of paper and then you absorb light by putting colors on it and you mix those together to create new colors and like this is kind of a concept that's also used for like painting like you start with something like like a plain surface um yeah and then like you always like this when you go to computers you you probably notice like triples of um of colors like for example this rgb triplet which you can visualize as this cube so like it's kind of like a position in that cube so like wherever you are in that cube you can specify with that location um and And then all the color models, you normally have three or four different values. Maybe you have seen those color models with the alpha channel to give you some opacity as well. This is all to create the same color on different devices. So this is another color model, HSL, which is basically hue, saturation, and lightness. And that was developed in the 70s. I guess it's not really used anymore, but it's just more advanced now. give you an idea like how that looks kind of in this like cylindrical um shape of like you on the outside um saturation from inside to the out and lightness from top to the bottom and then like online you will see all those like color pickers and like for the different programs that you use it will like look a little bit different but you can just like use different color models like here you see if like rgb and hsls like you can recalculate it and like different color models are better for like different colors than others but like it's always some kind of drawback on others so just to yeah talk slightly about human perception of colors like here you should all see like if you just take the same color we are quite sensitive to green light so like even though we have to like the same linear shade of color we see here like we we see green as more light than red and red more light than blue this is just because of like the human like like cone cells do not work the same as we like translate them to like some color models so this is just something really important to to like realize in the human eye may not be perfect for like some kind of computer model that you see um on the other side um like as i said before they all like those concept that we talked about are like kind of connected and related to each other so we also have this like saturation lightness dependency, which is quite interesting to see. If you see the hue, which is just a ring of it, and on the left we have low lightness that goes up on the right, and the saturation from the inside to the outside, then we just see something like a dark yellow is something we can't really see. And on the other side, if you check the bluish and purple, we can see just a lot of middle and high saturated colors. And some others may not be that good. And yeah, then coming back to Goethe, like warm and cool colors, which like he defined as the first person, like warm colors being something we see as like daylight or like sunset maybe, and cold colors being like kind of connected to like some gray overcast day or something. And this is like highly depends on your cultural influence. So like in different cultures, colors mean something different. So this is just something to be really aware of. um like the whole field of like color psychology is just used a lot in like marketing and branding so if you check like company logos and they normally have really good people there like especially the the big companies if you see some small companies you see some horrible logos and like horrible color choices and they all want to like tell you something um like it's some really cool stuff on the internet if you're like interested in like branding and marketing um so i get those colors like mean something so like you should be aware of that if you choose colors for your chart as well so yeah i guess like to just like wrap that all up into like some really easy points for you to like take take along on the road i created some really important parts here and then i have some do's and don'ts in the end and then i hope you all learn a lot to like make better charts in a short amount of time like you know i can't tell you like those other colors you should use it really depends but i hope you know after that like what it is like how you can get started easily so um like the first point being like don't use color if you don't have to like just try to make it gray um i found this really cool article which is called make gray your best friend which i really recommend all of you to read it's really cool written like they have some nice examples um and it's it's basically about like you should use as much gray as possible and you should use color only to highlight what is important um so this is an example of that blog um so like i would really recommend everybody reading that blog post to like get an idea and um yeah just use less colors in general it's just a really big advice i can give everybody here um second being um like use different colors for different data so like here you just see some like color harmonies or like something like pleasing um like aesthetically pleasing colors that go well together um but depending on your data and your problem you should be aware of like should maybe use different colors that are maybe like on the opposite of the wheel or maybe next to each other so like depends if you have like categorical data and diverging data sequential data like you should use colors that like go well with the data that you have at hand this is also like just something really important like if you just use default colors it will may lead to like some really false consequences in like what you think that means um next being like use um intuitive colors if you can um also like not always that easy like you just see like a world map with some like two like color maps here of like bluish and greenish colors being like green for the land and blue for the water if you would turn it around like i bet seeing that image will take like three seconds for you to understand it's like the globe or something um it's just sometimes really difficult and um yeah like just try to make something that's sensible um speaking can go to that also like you always in dashboards have those like traffic signals like this is just horrible uh in general but like you know like that goes into like being intuitive like it's not always that easy to to choose good colors for that um yeah like what i mentioned before like think about like human perception of colors like they create some kind of feeling um that's like a lot of like warm and cool colors like that may go well together or not um and think about like some cultural influence um like just different colors mean just something completely different like here i guess like in in europe um we have to see like red as law of exciting maybe like some danger but like in different countries it could just mean something completely completely different so like think about your audience like who will see that chart later um yeah then like another point which i think most people never do like included me is like think about missing values like if you have some um like null values like non-data and you just put it in there like that you see on the left um you may come to the conclusion by just looking at it that you have some data values for water whereas if you would exclude that and like make it visible like on the right you will just see better um yeah like there's no data in it like just to like something to think about and like i think the left one is prettier but it's maybe more wrong so like i guess this is like a really interesting field here um that you see and then uh yeah colorblindness that i haven't mentioned so far so like i was reading that around five percent of humans are at least partially colorblind like i don't know how many can see that um so it's just something to be aware of like many people like what i said before like traffic lights for example you have like green and red or like those like normal pure colors and this is just often really bad choice because like if like one out of 20 is not able to see your chart anymore like this is quite a lot so like it depends i guess on the audience as well um but it's quite easy to like choose colors which colorblind people can can um can see as well so it's just not really a lot of effort for you but it will just make it easier for everybody else so like another really practical tip for everybody here like i don't know who heard of the color brewer um which is like take one minute to create colors for your uh like specific problem and everybody's happy like it's a really easy website to use like you specify just like how many classes do you have what kind of data do you have like we have categories do we have some like diverging or like qualitative data um and then you can like see immediately how it looks like you can choose um you can like choose some options to make like print friendly and colorblind safe so it's like really it takes one minute and you can just export that into your python notebook or like some other tools um so it makes it just really really easy um to choose colors like that's like what i would recommend everybody like everybody has one minute to spend on the chart like i would say like there are many other tools available i just think this is the easiest to get started and the easiest to to like create quick colors for your visualization so yeah to finish that up um like just some more do's and don'ts and like a little bit more general um and then i included tons of links here so like if you want to like read more about all of that like their links here um so i guess there's like a lot to to do um so like to do first of all like take your time like if if you create charts like just don't like take the first one like don't use those default colors just take some time to to create your charts um and label the charts like really put in like labels on the axis give it a title um and i think nobody really puts text onto charts anymore which i think is quite bad because even yourself you see your own chart three weeks later and you have no idea what you did like just adding some text like some description on it will just make it easier for everybody um and then there's this new concept like i don't know how many of you here work with tableau um about like storytelling and those like tableau zen masters which are quite good at it it's like just they think about their data with some questions and answers in their mind to create some like story which just makes it easy for people to to understand so like if you're interested in storytelling just google tableau zen masters and you will find like a lot of cool visualization stories that really answer questions that you didn't have before then also like what i didn't talk about here is like chart types so like there's many different chart types there's really cool tool from the financial times that included in the links um which is like a public tableau dashboard about chart types like we didn't have time for that but like think about what chart type um is good for you to use and i guess it really depends on the problem if you don't have those examples but just some raw data it may not be that trivial to like choose which chart type you want to want to um use um then like the more complex your charts get maybe it's a good idea to sketch first like if you spend like one or two days and like making the chart look like it should and then somebody tells you like yeah like that's not what i had in mind that's maybe easier to like sketch first to see what what may happen uh for easy charts i guess it's not possible but if you grant those like fancy um thank you plots or something like that it makes sense to first sketch it to get a better idea if it even works um yeah as i said before like use as much gray as possible um use color only to highlight what's really important like what people should see and like see immediately and like what they should take along on the way um then on general like all those like um charts that like have access always start at zero it's super confusing if you don't um but it depends of course on the audience but like just in general it's just something really unintuitive to do um you should think about handling your missing values to some extent like if you don't think about it it will just do something that you may not be aware of um so it's just a good idea to like think about it or like just exclude it from the data but like think about it before you do it um think about your audience as well like if it's small audience it may be a little bit more complex it may be okay um as a guideline i would say check newspapers or like magazines like the economist or the new york times and the charts that they are using are normally good for like a big audience and they also have really good people in doing that um with like colors charts so i guess like this is just like always a good inspiration to get from like getting some really good charts and um yeah like learn matplotlib like i know it's horrible the syntax is really confusing um i try to do it but like it's really really difficult um just a lot of python libraries are based on matplotlib so at some point if you want to do something really specific you need to write matplotlib code and then it becomes just handy to know it um but i know it's really awful um and it's a lot but in general it's just like really helpful to know the more the better um Yeah, and I just, like, made a last-minute change of, like, yeah, talking about charts, not including that one. I don't know of you, who of you knows that chart, probably all of them. I don't even know. Okay. So, many people say this is the best chart ever from Minard, who was, like, visualizing the march from Napoleon to, like, Moscow. So, you put in here, like, six or seven dimensions, I guess, into two. And I guess there's, like, some stuff you can improve. Like, first of all, like, his handwriting is quite awful, I guess. but just to give you an idea of like you know like there's a lot of text here to explain so like what you see here is like the troops going from like uh like france to like moscow you see the size of the troop you see how many like the black line how many are wounded and like go back um you see the dates you see the location you see the temperature and line on the bottom um just to give you some idea like how do charts look like if they're good um and i just put it in here for the text because i think nobody puts text into charts anymore and they should do more and yeah just some like don't uh don't use 3d uh don't use pie charts normally i would say uh and don't use the full colors like this is probably the most horrible chart that i've ever seen so far and like that was on tv so um that's just really really bad um so i guess like you can all make something really much better than that but there is a lot of like people around them making really horrible charts like it's quite difficult to find good examples when it's just so much looks the same or it's like not really that good and like creating a perfect chart you know like even even that might not be perfect like there's always stuff to improve as always it's like personal preference and um yeah depends on you so like i hope you like learned a lot um i put in like tons of links here like where i got most of the information of the presentation and also some more so like if you're interested in that field um yeah like i hope you know a little bit more now, and you're all excited about using less colors, but good ones from now on. Thank you. Yeah, thank you very much. I think maybe one question, a short one. thank you for the talk I just want to know if you have a fallback in the case of let's say different beamers sometimes you go to a conference or you go to any kind of presentation you have to do the beamer is not showing good contrast the colors don't look like well so then again is there some kind of plan B you do or do you already research how those rooms and beamers look like? And even the size of the beamer sometimes matters. So choosing correct sizes. I know that's two questions now, but plan B is the question. For that presentation, I didn't, but I also didn't have time for that. But in general, I guess it's a good way, but I don't think many people have time to create different charts for different colors, but in general, it will be really good to be prepared for those changes. So I guess it depends on the audience. Like, if you have a big audience of people, it may be really good to have different charts. Like, if you have, like, you know, like, your, like, company presentation, that may be really good to have, like, different contrast colors. But there are, like, some tools available for contrast, like, to choose colors with, like, a high contrast, for example, if you want to show that. So, even if the beamer has not the best contrast, it will probably still look okay on a big beamer. okay so if you have more questions i think then it will be around the conference the next three days so thank you very much and thank him again please