Introduction to Data Visualization with Plotly in Python
Alex Scriven
Data Scientist
Hover information: The text and data that appear when your mouse moves over a data point
$$
By default hovermode = "closest"
"x"
or "y"
: adds a highlight on the x or y axis$$
"x unified"
/ "y unified"
: displays a line and a hover box showing all values on the x or y axis
hover_name
= A specified column that will appear in bold at the top of the hover box$$
hover_data
= A list of columns to include or a dictionary to include/exclude columns{column_name: False}
(this will exclude column_name
)💡 Hover columns don't need to be in the plot
$$
fig = px.scatter(revenues,
x="Revenue",
y="employees",
hover_name="Company",
hover_data=["age"])
fig.show()
hoverlabel
$$
hovertemplate
$$
$$
update_layout()
to control the legend$$
showlegend
= True
displays the default legendlegend
- takes a dictionary of propertiesx
, y
let us position the legend within the plot area (range from 0 to 1)bgcolor
(background color), borderwidth
, and font
$$
Check the documentation for more
$$
$$
fig.update_layout( "showlegend": True,
legend_title_text="All Companies"
legend=dict( x=0.7, y=0.8, bgcolor="rgb(246,228,129)")) })
Introduction to Data Visualization with Plotly in Python