Learn how to look up color hex values and update your Tableau preferences file to make the colors a permanent option on the Color Marks Card. You’ll see the code required to customize three different types of color palettes.
Code needed to add a custom color palette in your preferences.tps file:
<color-palette name=”Playfair Data TV Live Example” type=”regular”>
<color-palette name=”Playfair Data TV Categorical” type=”regular”>
<color-palette name=”Playfair Data TV Sequential” type=”ordered-sequential”>
<color-palette name=”Playfair Data TV Diverging” type=”ordered-diverging”>
Hi, this is Ryan with Playfair Data TV. And in this video, I’m going to show you how to create custom color palettes in Tableau. Before we get to the code and I show you how to do that, first it’s important to understand what are the three different types of color palettes that you can come across while you are authoring something in Tableau Desktop. So to illustrate, I’ve got this Sales by Sub-Category bar chart built from the Sample Superstore dataset.
If I were to add a discrete dimension, like Sub-Category, to the Color Marks Card, we will see the first type of color palette appear. I call this a Discrete color palette, because we’re building this with a discrete dimension, and we have discrete or unique colors for each of the dimensions members. Once we get into the code, you’ll see that Tableau calls this a ‘Regular’ color palette. You can modify these colors by double-clicking on the color legend or clicking the Color Marks Card will open up- and clicking Edit Colors- will open up the same dialog box where you can remap colors.
You can remap the colors to any palette in these dropdowns, so that’s exactly what I’m going to show you how to do. And, in fact, I’ve got one custom Regular palette, which is what Tableau calls it here, called Playfair Data TV Categorical. That’s the first type of custom palette that you can create. I’m going to X out of this, and instead of coloring this bar chart by Sub-Category, I’m going to color the values by their sales amounts by dragging the Sales measure this time to the Color Marks Card.
And notice we get a different type of color legend this time. It’s a consequence of this Sales pill being green or continuous. If that concept is new to you, I highly encourage you to check out the video here at Playfair Data TV called Tableau Classification: Discrete Versus Continuous. But now we’ve got our second type of color palette, and it is a Continuous color palette. And Tableau’s term for this is an ‘Ordered Sequential’ color palette, because these colors go in a sequential order. Just like the Discrete color palette, you can double-click on this legend, and you can change the end of the spectrum that the continuous palette is based on.
You can also use this dropdown to select a custom palette. I should point out that many of these come with Tableau, but before this video, I have already gone ahead and added a couple. This is where your custom color palettes will show up. So notice I’ve got Playfair Data TV Sequential. So I’ve chosen the color and the code. It’s a custom value. Let’s say we wanted to make these colors in brand. I could find that color value, put it into the code so that it’s always available to me here in Tableau Desktop. The third type of color palette is called an ‘Ordered Diverging’ palette.
Instead of having one value at one end of the spectrum, and having everything be continuous in one direction, you can make a diverging color palette where you have a color on two ends of the spectrum. This is best used when you’ve got positive and negative values. So to illustrate this one, I’m going to drag the Profit measure to the Color Marks Card. And you can see that third type of palette. There’s now a tick mark in the middle of that diverging color palette and we have two sides now.
For negative values, we go from gray to a dark orange. For positive values, we go from gray to a dark blue. Just like the first two, I can modify these colors in two different ways. I can either double-click on the color legend, or click on the Color Marks Card and click Edit Colors. It takes me to the exact same dialog box where I can now either choose different colors here, but that’ll be a one off. That’ll only be relevant or saved in this one case. The other option is to use this dropdown menu to select something that’s more permanent.
These are color palettes that are in the code, including a custom palette. So, again, I had added this before the video, but I’m going to show you exactly how to add one of these custom color palettes. I just thought it was important for you to know what the three different versions were. By the way, the proper term for this third and final palette is called ‘Ordered Diverging’. The proper name will be very important for you, because you’ll need to know exactly how it is spelled to get it in to the code so that it becomes a permanent option as a color selection.
To show you during this video, I’m just going to add one more palette, and it will be called a Regular color palette. I’m going to click Cancel, and I’m going to make this discrete colors, again. Maybe, I will throw Region onto the Color Marks Card. And let’s just go pick out a few colors that we like. I’m just going to completely do this randomly now on the fly here. But let’s say we wanted to take one of the colors from different palettes. So we wanted each region to be colored a certain color, but we like colors that exist across palettes.
We’re going to make this easier for us to use in the future by creating a custom color palette that contains whatever these four colors we end up on are. Let’s say, just to make it easy, that to start with, we’ll keep Central as that default blue. The most important thing to record when you are creating a custom color palette is the six-digit hex code for that color. You can easily get to that by just double-clicking on the dimension member. And I’m on a PC, this does look slightly different on a Mac.
But on a PC, it will open this little color generator, and here’s where the six-digit hex code is. That will be very important for us to record for each of our four colors for this palette. To create a custom color palette in Tableau, navigate to your Documents folder. Again, I’m on a PC, so this will look slightly different on a Mac. But on a PC, go to your Documents folder. And within your Documents folder, when you download Tableau, you will automatically get a new folder called My Tableau Repository.
Within that Tableau repository is a file called preferences.tps. This is where your colors exist, at least your custom color palettes exist. To modify this file, right-click on it and open it with Notepad. If you’re opening this file for the first time, you’ll likely just see this first line of code. But this is where you add custom color palettes. If you want to add a custom color palette, you first need to open up a new set of preferences. So there’s the code there. Open bracket, workbook, closed bracket.
Next line, open bracket, preferences, closed bracket. And at the bottom, I just take those same pieces of code and I close them. So notice there’s a slash before each one. So that code is there regardless of how many color palettes you’ve got. If you are starting with your very first custom color palette, you will need to open the preferences code, as well as close it at the bottom. And then in between, what you see are the custom color palettes that I already alluded to.
We had one called Playfair Data TV Categorical. It’s a Regular palette. We have one called Playfair Data TV Sequential. It is an Ordered Sequential palette. And then we have one called Playfair Data TV Diverging, and that is an Ordered Diverging palette. Those three words, so the types of palettes, are also very important to record, because they will behave differently in Tableau. If you type regular, that will be a discrete color palette, so unique colors per dimension member.
If you choose ordered sequential, these colors will go in order, from left to right in sequential order, which is why it’s called that. And if you choose ordered diverging, these will also go in order. So you’ll want for negative values, something that represents negatives as the first value, something that represents positives as the last value. And, in this case, I had a value in the middle. It goes in order, but they will be on a diverging scale. Let’s go ahead and add one just to show you how this works.
For each palette, you need to open the palette with this code. So color palette name equals, and you can call this whatever you want. I’ll call this Playfair Data TV Live Example. And we’ll make it a Discrete color palette, so we’ll leave that as regular, and you also have to close the palette. So every color palette will have these two pieces of code. The first one opens the palette, you give it a name, as well as a type. You then need to close each color palette.
Very important to both open and close the code. Otherwise, it won’t recognize things and it could, in fact, break something. So we want to open the palette, as well as close the palette. Then what goes in between are each of the colors that you want represented in that palette. And the code is color, and an open bracket, the six digit hex code including the number sign, and then you close the color. Notice I’ve just tabbed my custom colors here to make them easier to read. That part is optional.
But if I was wanting to make a four-color palette, I could copy and paste this code four times and then simply look up the hex values for each of the four colors that I want represented. So back in Tableau Desktop, we already have the first one. This is the first default blue. So I’ll just paste that in here as the first color. You saw that I overrode that. I’ll move on and choose a second color. Let’s say for East, we want to get a little bit more creative, maybe go to this Superfishel Stone palette and choose a brighter orange.
Once that orange is selected, I can double-click on it and copy that hex value. I’ll put that back in here as the second color and move back to Tableau Desktop to choose a third color for South. Let’s say for South, we’ll go to the Jewel Bright palette, and we’ll make it this kind of teal color. So click the dimension member, then click the color. Once it is changed, I can double-click and copy that hex value, as well. Paste that in as a third color, and move back to choose my fourth and final color.
Let’s just pretend that West isn’t as big of a focus, so we’ll just give it a gray color. I’ll click West, go to my Seattle Grays palette, which is, by the way, one of the default color palettes in Tableau. I will copy that out and go to paste it into my preferences file. So that is all of the code. Just a reminder, when you open the file, you’ll likely just see this first line of code. If it is your very first palette, open the workbook, open the preferences, make sure you also close the preferences, close the workbook, and then every single palette in between. I don’t even know that there is a limit to this.
In other versions of Tableau, I’ve got 20 or so different custom color palettes. This is just a training example, so I’ve got four in here at the moment, but they all have a similar syntax. You open the color palette, you give it a name, and you give it a type. You then close the color palette. By the way, I will be providing this syntax in the related content below this video. Then between opening and closing the color palette, you simply type in the six digit hex codes.
Make sure you save the preferences file. And I’m going to click OK here, and I will also save this file. These colors won’t appear until you close and reopen Tableau, so I actually need to go ahead and close Tableau Desktop. And now let’s go modify these colors and see if we have that new palette available to us. I’ll click on the Color Marks Card, click Edit Colors, and use this dropdown. And your custom color palettes will always show up at the bottom of this list.
And, sure enough, we have something new called Playfair Data TV Live Example. That’s the new Regular, or what I call Discrete, color palette. Now remember, when we were looking up these colors, we already mapped those. So just to show you that those are always available to us and give you one more example, I’m going to cancel out of this. And instead of coloring the bars by Region, I will color them by, say, Shipping Mode. I’ll drag that dimension to the Color Marks Card.
By default, it goes back to the default Tableau color palette. But now if I click in here to modify those discrete colors, my newly created custom color palette will be listed here, and I can remap these. Just click on each dimension member and choose the new custom color, click OK, and we’ve just modified the colors with something custom that we had available to us because we modified the code of our preferences file.
This has been Ryan with Playfair Data TV – thanks for watching!