我与Seaborn创建了一个情节:
# create some random data
N = 20
rand_matrix = np.asarray([random.randrange(1,11)/10 for _ in range(1, N*N+1) ]).reshape(N,N)
data = np.flip(np.triu(rand_matrix), 1)
df = pd.DataFrame(data, index=pd.date_range(start='2015-01-01', freq='MS',\
periods=N), columns = range(1,N+1))
df[1]=1
# seaborn plot
%matplotlib inline
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(20,20))
sns.heatmap(data = df,
annot = True,
vmin = 0.0,
vmax = 1.0,
cmap = 'PuBuGn')
这是创建Plotly图的方式:
import plotly.offline as py
import plotly.graph_objs as go
py.init_notebook_mode(connected=True)
data = [
go.Heatmap(
z=df.values,
x=df.columns.tolist(),
y=df.index.tolist()
)
]
layout = go.Layout(
xaxis = dict(ticks='', nticks=N),
yaxis = dict(ticks='', nticks=N))
fig = go.Figure(data=data, layout=layout)
py.iplot(fig)
我有以下问题:
答案 0 :(得分:1)
2。。如何将较早的数据显示在顶部?
fig.update_yaxes(autorange="reversed")
3。。如何获得显示在热图中的数据标签?
ff.create_annotated_heatmap()
4。是否可以进行总体优化?
这里没有快速修复方法。
情节:
密谋:
from plotly.offline import iplot
import plotly.graph_objs as go
import plotly.figure_factory as ff
#py.init_notebook_mode(connected=True)
data = [
go.Heatmap(
z=df.values,
x=df.columns.tolist(),
y=df.index.tolist()
)
]
font_colors = ['white', 'black']
fig = ff.create_annotated_heatmap(z=df.values, colorscale='Jet', font_colors=font_colors)
fig.update_layout( yaxis = dict(ticks='', nticks=N))
# Make text size smaller
for i in range(len(fig.layout.annotations)):
fig.layout.annotations[i].font.size = 8
# reverse scales
fig.update_yaxes(autorange="reversed")
fig.show()