Get startedGet started for free

Editing plot axes

1. Editing plot axes

In this lesson, you will learn how to adjust and format the axes of your plots. Let's get started!

2. Our dataset

For this lesson, we have aggregated the penguin data by species, averaging their flipper lengths. But the column names aren't exactly presentation-ready.

3. The default axis titles

Let's create a basic bar chart. We pass the correct column names to avoid an error. The plot works - but it could use more polished axis titles.

4. Editing axis titles

Plotly offers shortcut methods to format elements like axes. One option is using update_xaxes() and update_yaxes() with the title_text argument. Another way is using update_layout() with a dictionary that targets layout elements - like the axis titles. For consistency, we'll stick with update_layout().

5. Cleaning up our plot

Both approaches produce cleaner, more professional-looking axes titles.

6. Which method to use?

So, which one should you use? The shortcut methods are quick and simple for basic updates. But update_layout() gives you complete control - letting you adjust font size, style, color, angle, and more. For a full list of styling options, check the Plotly documentation.

7. Editing axes ranges

Sometimes, we want to set a specific axis range instead of using Plotly's default. In our bar chart, the values are so close together that the differences are hard to spot. To overcome this, let's set the y-axis to start at 150 and end after the maximum of all values (with a small buffer). We use the general update_layout method and edit the yaxis argument, which has a range argument. This is a list of two values, the min and max of the range.

8. Our new axes ranges

We now get our bar chart with specific axes. Nice stuff.

9. Data scale issues

Sometimes, instead of being very close, you may want to visualize data where the values of the categories are very different. Let's use this recent data of the top 10 countries by the number of billionaires. You can already see there is a huge gap between the top and bottom entries,

10. Our scale problem

If we just plot the values as-is, the top few bars dominate, and the rest are barely visible.

11. The log scale

This is where the logarithmic, or log scale, can help. It's often used to plot data with large value differences. Here's an example showing the number of Internet hosts between 1981 and 2012. Notice how the y-axis ticks increase exponentially - each is ten times the previous.

12. Using log with our data

Let's improve our billionaire chart using a log scale. Plotly has convenient arguments for easily transforming the scale to a log scale. We will use the log_y argument, as our x-axis is categorical. Much better. Now we can clearly see the differences between all the countries.

13. Log scale: a word of warning

Just remember - log scales can be misleading for audiences unfamiliar with them. People may think the values are closer together than they actually are. Always consider your audience when choosing how to visualize your data.

14. Let's practice!

Let's practice editing the axes of some plots in Plotly!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.