Disable Hover Information in plotly Using Python (Example)


Howdy folks! I welcome you to another interesting plotly tutorial using the Python programming language. This tutorial promises to leave you learning something new about using plotly in Python, which is an interactive data visualization library. In this tutorial, I will show you how you can disable hover information in your plotly graph.

Here is a sneak preview of what we are going to do in this tutorial:

Let’s dive right into it!


Download & Install plotly Library

To use the Python plotly library, you need to first download and install the library in your Python programming environment. Therefore, in your favorite Python programming IDE, run the line of code below:

pip install plotly

The line of code above will install plotly in your Python coding environment along with all its dependencies.

Import plotly Library

Now that we have downloaded and installed plotly, let us now import it so that we can have access to its plot-building functions, one of which we will make use of shortly in this tutorial. Therefore, run the line of code below to import plotly:

import plotly.express as px


Build Basic Line Plot

We can now go on to build a basic line plot. But just before we build our line plot, we will also need to install and load the Python pandas library, which will enable us to build the DataFrame that we are going to visualize in this project. So, in your IDE, run the lines of code below:

pip install pandas
import pandas as pd

Now, let us build and examine our sample DataFrame by running the lines of code below:

df = pd.DataFrame({"Price":[250,530,300,850,400,670,750],
#    Price Year
#0    250  2011
#1    530  2012
#2    300  2013
#3    850  2014
#4    400  2015
#5    670  2016
#6    750  2017

Great! We can now finally build our basic line plot. In your IDE, run the lines of code below:

fig = px.line(df,x = "Year",y = "Price",title = "Car Brand Manufacture Year & Prices")

If you move your mouse over the plot, you will see the plot’s hover information. This is the default behavior of the plotly library. Nevertheless, it is possible to disable this feature, as we will see in the next section.

Disable Hover Info

To disable the hover information feature of your plotly visualization, you only need to define two new arguments in the update_traces() function, as demonstrated in the code below:

fig = px.line(df,x = "Year",y = "Price",title = "Car Brand Manufacture Year & Prices")
                  hovertemplate = None,
                  hoverinfo = "skip")

Now when you hover over the plot, you do not see any hover information because it has been disabled by defining hovertemplate = None and hoverinfo = "skip" in the update_traces() function.

And that is how to disable the hover information in your plotly graph using Python. This can also be applied to all other visualizations created in plotly. You may play around with other visualizations and try to disable their hover information as well.

Well, I am hoping this tutorial has left you learning something new. If that is true, then be sure to check out other plotly in Python tutorials on Statistics Globe. Thanks, and I will see you in the next one!


Video, Further Resources & Summary

Do you need more explanations on how to disable the hover information in plotly using Python? Then you should have a look at the following YouTube video of the Statistics Globe YouTube channel.

In the video, we explain in some more detail how to disable the hover information in plotly using Python.


The YouTube video will be added soon.


Furthermore, you could have a look at some other tutorials on Statistics Globe:

This post has shown how to disable hover information in plotly using Python. In case you have further questions, you may leave a comment below.


R & Python Expert Ifeanyi Idiaye

This page was created in collaboration with Ifeanyi Idiaye. You might check out Ifeanyi’s personal author page to read more about his academic background and the other articles he has written for the Statistics Globe website.


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.