Plotly绘制树状热力图(treemap)Plotly实例教程

Posted K同学啊

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Plotly绘制树状热力图(treemap)Plotly实例教程相关的知识,希望对你有一定的参考价值。

从DataFrame获取数据绘制

import plotly.express as px
import pandas as pd

#任意的多组列表
a = [5,8,16,32,64,128,256,256,5,8,16,32,64,128,256,256]
b = ["a","g","j","i","g","f","h","b","a","c","c","a","g","f","g","g"]

#字典中的key值即为csv中的列名
data_dict = 'a_name':a,'text':b

#设置DataFrame中列的排列顺序
#如果无需重命名,columns这一参数可以省略
dataFrame = pd.DataFrame(data_dict, columns=['a_name', 'text'])

dataFrame.head(3)

b = dataFrame['text'].value_counts().index.tolist()
a = dataFrame['text'].value_counts().tolist()
print(a,b)

row = pd.DataFrame('scenario' : [])
row["scenario"] = b
row["Number"]   = a
fig = px.treemap(row, path= ["scenario"], values="Number",title='Tree of Mentions')
fig.show()

从列表List中获取数据绘制

import plotly.express as px
import pandas as pd

a = [5,8,16,32,64,128,256,256,5,8,16,32,64,128,256,256]
b = ["a","g","j","i","g","f","h","b","a","c","c","a","g","f","g","g"]

row = pd.DataFrame('scenario' : [])
row["scenario"] = b
row["Number"]   = a
fig = px.treemap(row, path= ["scenario"], values="Number",title='Tree of Mentions')
fig.show()

以上是关于Plotly绘制树状热力图(treemap)Plotly实例教程的主要内容,如果未能解决你的问题,请参考以下文章

R语言数据热力图绘制实战(基于原生R函数ggplot2包plotly包)

Python热力图绘制方法—新手教程

Android高德之旅(10)绘制热力图

Winform WPF 绘制热力图组件 效果媲美B/S 热力图

Python绘制热力图

R语言绘图:在地图上绘制热力图