Reputation: 183
When I'm hovering on a plot in Heatmap it is showing axis as x, y, z.
But I wanted it to be like Year, Month, No. of Passengers respectively
Here is my code:
import pandas as pd
import plotly.offline as pyo
import plotly.graph_objs as go
flights_data_csv = pd.read_csv("flights.csv")
data = [go.Heatmap(x=flights_data_csv["year"],
y=flights_data_csv["month"],
z=flights_data_csv["passengers"].values.tolist(),
colorbar=dict(title="Passengers traveled <br>by Flights"),
colorscale="jet",
zmin=100,
zmax=650)]
layout = go.Layout(title="Exercise of HeatMaps <br>For Showing Flights details",
title_x=0.5)
fig = go.Figure(data, layout)
pyo.plot(fig, filename="Flights Heatmaps.html")
Upvotes: 2
Views: 453
Reputation: 35686
Add a hovertemplate and specify the format:
Year:%{x}<br>Month:%{y}<br>Passengers:%{z}
Variables are referenced by %{x}
, %{y}
, and %{z}
respectively, otherwise html can be used to format the display.
data = [
go.Heatmap(x=flights_data_csv["year"],
y=flights_data_csv["month"],
z=flights_data_csv["passengers"],
colorbar=dict(title="Passengers traveled <br>by Flights"),
colorscale="jet",
zmin=100,
zmax=650,
hovertemplate='Year:%{x}<br>Month:%{y}<br>Passengers:%{z}',
name='')
]
name
is set to the empty string (name=''
), otherwise trace 0
will appear as the label:
Upvotes: 1