A Clean Style for Plotly Charts
By: Patrick Coffey
Tags: Data Visualization, Data Science, Plotly, Charts, Python

To see how this works, let's create a toy dataset. See below for the required imports and the generation of the dataset to help illustrate how to make plotly charts look more professional.

For this article’s purposes, we will give an example using a bar chart since it is a good choice to encode two categorical variables and a numeric value. We will encode the Animals along the X-axis, the Heights along the Y-axis, and using colour to encode the number of legs.

Image by Patrick Coffey (Plotly)

While the above chart doesn't have anything inherently wrong with it, it just looks a little bit boring and generic. I find the grey coloured background to be a little too dark for my liking and the title and label fonts are just a bit too bland. Let's define a custom style template and apply it to our chart to fix some of those problems.

In the above custom style template, we are changing the title font to Lato because it is a nice readable font, which is also quite compact in terms of its width. This allows titles to be longer without going off the charts' edges and is a simple way to describe better the story the chart is attempting to convey.

Typography is an art I can't wrap my head around; I opt for the trial and error approach!

Nunito is a font I found by this method, and I use it for the axis labels. To me, it looks like a slightly squarer version of Comic Sans, which ironically seems to look quite professional on a chart. If your labels are long, then it might be a good idea to try Lato here since it is a slightly condensed font and will fit more characters in the same width. Let's see what our chart looks like when we apply this styling!

Image by Patrick Coffey (Plotly)

Alright, now we are starting to get somewhere! Apart from the fonts, we have made a few other changes to make the chart a little nicer. We have applied a different colour scheme; I generally opt for the G10 colours scheme built into plotly as a starting point. It seems to be widely accepted by people I produce charts for and works in many different aesthetics. It can be a little bright, but I think this lets our encoded data stand out from the other chart elements. The background colour has been switched to white.

This allows for a larger negative contrast from the encoded data, which again helps it “pop”.

The Y-axis grid lines use a very light shade of grey and are very thin; this allows them to be still seen but not to add too much cognitive load to the reader when interpreting this chart. The labels have received a similar treatment. They have been greyed slightly not to distract the reader from the data, they are still there for reference when the reader needs them, but they don't subconsciously draw the users eyes away from the data until they are ready.

Another common trick I use is to create a subtitle for my charts. This allows me to have a nice short and succinct title while describing important information like the data range or collection method in the subtitle, which adds some nice context to the chart (or sometimes is even mandatory when dataset attribution is required!).

In plotly, we can achieve a subtitle by adding some HTML formatting to the title string.

We will Bold the title, emphasize it, add a line break, then use a span element with a reduced font size to add a subtitle.

Image by Patrick Coffey (Plotly)

And that's it! You can now make professional-looking charts in plotly, using my opinionated custom styling as a starting point. Good luck and happy plotlying!