I’m trying to graph a heatmap of class period attendance by student by referencing a pandas dataframe “graph-me”. Here is the code for the Heatmap data
The problem is that my Z values fill in horizontally when I expected them to fill in vertically. I have over 100 values on my y-axis and can’t manually change this. How do I flip the reference of my Z-values without changing my x or y axis?
I’m just learning Plotly, the curve has been steep so I hope my question is understandable
I generated random data to illustrate how a heatmap that you intend to plot looks like.
If Heatmap.x has 9 elements (periods), and Heatmap.y, 100 student names, then z must be an array of 100 rows and 9 columns.
Please copy the code below, run it, and let us know if you want more details:
import numpy as np
from random import choice
import plotly.graph_objs as go
graph_me = {'Student Name': [f'Student {j}' for j in range(1, 101)]}
for k in range(1,10):
graph_me[f'Percentage P{k}']= np.random.randint(10, 60, 100)
#graph_me['Percentage P1']
z = np.array([graph_me[f'Percentage P{k}'] for k in range(1,10)]).T
print(z.shape)
heat = go.Heatmap(x=[f'Period {k}' for k in range(1,10)],
y=graph_me['Student Name'],
z=z, coloraxis='coloraxis')
fig = go.Figure(heat)
fig.update_layout(width=800, height=1400,
coloraxis =dict(colorscale='matter',
colorbar_thickness=25,
colorbar_title='%'),
yaxis_autorange='reversed',
xaxis_tickangle=-45)
fig.show()