Data visualization analysis with pyecharts

1. Use the following JSON data to draw tree diagram and rectangular tree diagram. data = [{ "name": "flare", "children":...

1. Use the following JSON data to draw tree diagram and rectangular tree diagram.
data = [{
"name": "flare",
"children": [
{
"name": "flex",
"children": [
{"name": "FlareVis", "value": 4116}
]
},
{
"name": "scale",
"children": [
{"name": "IScaleMap", "value": 2105},
{"name": "LinearScale", "value": 1316},
{"name": "LogScale", "value": 3151},
{"name": "OrdinalScale", "value": 3770},
{"name": "QuantileScale", "value": 2435},
{"name": "QuantitativeScale", "value": 4839},
{"name": "RootScale", "value": 1756},
{"name": "Scale", "value": 4268},
{"name": "ScaleType", "value": 1821},
{"name": "TimeScale", "value": 5833}
]
},
{
"name": "display",
"children": [
{"name": "DirtySprite", "value": 8833}
]
}
]
}]

from pyecharts import options as opts from pyecharts.charts import Tree data = [{ "name": "flare", "children": [ { "name": "flex", "children": [ {"name": "FlareVis", "value": 4116} ] }, { "name": "scale", "children": [ {"name": "IScaleMap", "value": 2105}, {"name": "LinearScale", "value": 1316}, {"name": "LogScale", "value": 3151}, {"name": "OrdinalScale", "value": 3770}, {"name": "QuantileScale", "value": 2435}, {"name": "QuantitativeScale", "value": 4839}, {"name": "RootScale", "value": 1756}, {"name": "Scale", "value": 4268}, {"name": "ScaleType", "value": 1821}, {"name": "TimeScale", "value": 5833} ] }, { "name": "display", "children": [ {"name": "DirtySprite", "value": 8833} ] } ] }] c = ( Tree() .add("", data) .set_global_opts(title_opts=opts.TitleOpts(title="Tree-Basic example")) ) c.render("tree_base.html")

from pyecharts import options as opts from pyecharts.charts import TreeMap data = [{ "name": "flare", "children": [ { "name": "flex", "children": [ {"name": "FlareVis", "value": 4116} ] }, { "name": "scale", "children": [ {"name": "IScaleMap", "value": 2105}, {"name": "LinearScale", "value": 1316}, {"name": "LogScale", "value": 3151}, {"name": "OrdinalScale", "value": 3770}, {"name": "QuantileScale", "value": 2435}, {"name": "QuantitativeScale", "value": 4839}, {"name": "RootScale", "value": 1756}, {"name": "Scale", "value": 4268}, {"name": "ScaleType", "value": 1821}, {"name": "TimeScale", "value": 5833} ] }, { "name": "display", "children": [ {"name": "DirtySprite", "value": 8833} ] } ] }] c = ( TreeMap() .add("Presentation data", data) .set_global_opts(title_opts=opts.TitleOpts(title="TreeMap-Basic example"))) c.render("treemap_base.html")


2. Draw correlation matrix of iris data
Scatter matrix`

import pandas as pd import matplotlib.pyplot as plt import seaborn as sns iris=pd.read_csv("iris.csv") g=sns.pairplot(iris,hue='Species', vars=['Sepal.Width','Sepal.Length','Petal.Length','Petal.Width'], palette="husl", markers=["o", "s", "D"])


3. Mark the sales data of each province with dots on the map.
The data are as follows:
province = ['guangdong ',' Hubei ',' Hunan ',' Sichuan ',' Chongqing ',' Heilongjiang ',' Zhejiang ',' Shanxi ',' Hebei ',' Anhui ',' Henan ',' Shandong ',' Tibet ']
data = [(i, random.randint(50, 150)) for i in province]

from pyecharts import options as opts from pyecharts.charts import Map from pyecharts.faker import Faker import random province = ['Guangdong', 'Hubei', 'Hunan', 'Sichuan', 'Chongqing', 'Heilongjiang', 'Zhejiang', 'Shanxi', 'Hebei', 'Anhui', 'Henan', 'Shandong', 'Tibet'] data = [(i, random.randint(50, 150)) for i in province] c = ( Map() .add("",data, "china") .set_global_opts( title_opts=opts.TitleOpts(title="Sales data by province"), legend_opts=opts.LegendOpts(is_show=False), visualmap_opts=opts.VisualMapOpts(max_=150,min_=50, is_piecewise=True), ) ) c .render("map_visualmap_piecewise.html")


4. Draw a geographical hot spot map to show the number of stores of a chain enterprise in each city of Hubei Province.
The data are as follows:
province = ['wuhan ',' Shiyan ',' Ezhou ',' Yichang ',' Jingzhou ',' Xiaogan ',' Huangshi ',' Xianning ',' Xiantao ']
data = [(i, random.randint(50, 150)) for i in province]

from pyecharts import options as opts from pyecharts.charts import Geo from pyecharts.globals import ChartType import random province = ['Wuhan', 'Shiyan', 'Ezhou', 'Yichang', 'Jingzhou', 'Filial piety', 'Yellowstone', 'Xianning', 'peach of immortality'] data = [(i, random.randint(50, 150)) for i in province] geo = (Geo() .add_schema(maptype="Hubei") .add("Number of stores", data, type_=ChartType.HEATMAP)#Hot spot map .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( visualmap_opts=opts.VisualMapOpts(max_=150,min_=50,is_piecewise=True), legend_opts=opts.LegendOpts(is_show=False), title_opts=opts.TitleOpts(title="Number of stores of a chain enterprise in cities of Hubei Province")) ) geo.render("html")


Draw word cloud map (data: word_data.csv)

import pandas as pd import pyecharts.options as opts from pyecharts.charts import WordCloud data = pd.read_csv("word_data.csv") words = list(data["category"]) views = list(data["comments"]) data_pair=[(i , j) for i ,j in zip(words ,views)] c = ( WordCloud() .add(series_name="Cloud of words", data_pair=data_pair , word_size_range=[6, 66]) .set_global_opts( title_opts=opts.TitleOpts( title="Cloud of words", title_textstyle_opts=opts.TextStyleOpts(font_size=23) ), tooltip_opts=opts.TooltipOpts(is_show=True), ) ) c.render("Cloud of words.html")


Draw theme River Map
The data are as follows:
datax = ['Branch 1', 'branch 2', 'branch 3', 'branch 4', 'Branch 5', 'branch 6']
datay = [
['2015 / 11 / 08 ', 10,' Branch 1 '], ['2015 / 11 / 09', 15, 'Branch 1'], ['2015 / 11 / 10 ', 35,' Branch 1 '],
['2015 / 11 / 14 ', 7,' Branch 1 '], ['2015 / 11 / 15', 2, 'Branch 1'], ['2015 / 11 / 16 ', 17,' Branch 1 '],
['2015 / 11 / 17 ', 33,' Branch 1 '], ['2015 / 11 / 18', 40, 'Branch 1'], ['2015 / 11 / 19 ', 32,' Branch 1 '],
['2015 / 11 / 20 ', 26,' Branch 1 '], ['2015 / 11 / 21', 35, 'Branch 1'], ['2015 / 11 / 22 ', 40,' Branch 1 '],
['2015 / 11 / 23 ', 32,' Branch 1 '], ['2015 / 11 / 24', 26, 'Branch 1'], ['2015 / 11 / 25 ', 22,' Branch 1 '],
['2015 / 11 / 08 ', 35,' branch 2 '], ['2015 / 11 / 09', 36, 'branch 2'], ['2015 / 11 / 10 ', 37,' branch 2 '],
['2015 / 11 / 11 ', 22,' branch 2 '], ['2015 / 11 / 12', 24, 'branch 2'], ['2015 / 11 / 13 ', 26,' branch 2 '],
['2015/11/14', 34, 'branch 2'], ['2015/11/15', 21, 'branch 2'], ['2015/11/16', 18, 'branch 2'],
['2015 / 11 / 17 ', 45,' branch 2 '], ['2015 / 11 / 18', 32, 'branch 2'], ['2015 / 11 / 19 ', 35,' branch 2 '],
['2015 / 11 / 20 ', 30,' branch 2 '], ['2015 / 11 / 21', 28, 'branch 2'], ['2015 / 11 / 22 ', 27,' branch 2 '],
['2015 / 11 / 23 ', 26,' branch 2 '], ['2015 / 11 / 24', 15, 'branch 2'], ['2015 / 11 / 25 ', 30,' branch 2 '],
['2015 / 11 / 26 ', 35,' branch 2 '], ['2015 / 11 / 27', 42, 'branch 2'], ['2015 / 11 / 28 ', 42,' branch 2 '],
['2015 / 11 / 08 ', 21,' branch 3 '], ['2015 / 11 / 09', 25, 'branch 3'], ['2015 / 11 / 10 ', 27,' branch 3 '],
['2015 / 11 / 11 ', 23,' branch 3 '], ['2015 / 11 / 12', 24, 'branch 3'], ['2015 / 11 / 13 ', 21,' branch 3 '],
['2015 / 11 / 14 ', 35,' branch 3 '], ['2015 / 11 / 15', 39, 'branch 3'], ['2015 / 11 / 16 ', 40,' branch 3 '],
['2015 / 11 / 17 ', 36,' branch 3 '], ['2015 / 11 / 18', 33, 'branch 3'], ['2015 / 11 / 19 ', 43,' branch 3 '],
['2015 / 11 / 20 ', 40,' branch 3 '], ['2015 / 11 / 21', 34, 'branch 3'], ['2015 / 11 / 22 ', 28,' branch 3 '],
['2015 / 11 / 14 ', 7,' branch 4 '], ['2015 / 11 / 15', 2, 'branch 4'], ['2015 / 11 / 16 ', 17,' branch 4 '],
['2015 / 11 / 17 ', 33,' branch 4 '], ['2015 / 11 / 18', 40, 'branch 4'], ['2015 / 11 / 19 ', 32,' branch 4 '],
['2015 / 11 / 20 ', 26,' branch 4 '], ['2015 / 11 / 21', 35, 'branch 4'], ['2015 / 11 / 22 ', 40,' branch 4 '],
['2015 / 11 / 23 ', 32,' branch 4 '], ['2015 / 11 / 24', 26, 'branch 4'], ['2015 / 11 / 25 ', 22,' branch 4 '],
['2015 / 11 / 26 ', 16,' branch 4 '], ['2015 / 11 / 27', 22, 'branch 4'], ['2015 / 11 / 28 ', 10,' branch 4 '],
['2015 / 11 / 08 ', 10,' Branch 5 '], ['2015 / 11 / 09', 15, 'Branch 5'], ['2015 / 11 / 10 ', 35,' Branch 5 '],
['2015 / 11 / 11 ', 38,' Branch 5 '], ['2015 / 11 / 12', 22, 'Branch 5'], ['2015 / 11 / 13 ', 16,' Branch 5 '],
['2015 / 11 / 14 ', 7,' Branch 5 '], ['2015 / 11 / 15', 2, 'Branch 5'], ['2015 / 11 / 16 ', 17,' Branch 5 '],
['2015 / 11 / 17 ', 33,' Branch 5 '], ['2015 / 11 / 18', 40, 'Branch 5'], ['2015 / 11 / 19 ', 32,' Branch 5 '],
['2015 / 11 / 20 ', 26,' Branch 5 '], ['2015 / 11 / 21', 35, 'Branch 5'], ['2015 / 11 / 22 ', 4,' Branch 5 '],
['2015 / 11 / 23 ', 32,' Branch 5 '], ['2015 / 11 / 24', 26, 'Branch 5'], ['2015 / 11 / 25 ', 22,' Branch 5 '],
['2015 / 11 / 26 ', 16,' Branch 5 '], ['2015 / 11 / 27', 22, 'Branch 5'], ['2015 / 11 / 28 ', 10,' Branch 5 '],
['2015 / 11 / 08 ', 10,' branch 6 '], ['2015 / 11 / 09', 15, 'branch 6'], ['2015 / 11 / 10 ', 35,' branch 6 '],
['2015 / 11 / 11 ', 38,' branch 6 '], ['2015 / 11 / 12', 22, 'branch 6'], ['2015 / 11 / 13 ', 16,' branch 6 '],
['2015 / 11 / 14 ', 7,' branch 6 '], ['2015 / 11 / 15', 2, 'branch 6'], ['2015 / 11 / 16 ', 17,' branch 6 '],
['2015 / 11 / 17 ', 33,' branch 6 '], ['2015 / 11 / 18', 4, 'branch 6'], ['2015 / 11 / 19 ', 32,' branch 6 '],
['2015 / 11 / 20 ', 26,' branch 6 '], ['2015 / 11 / 21', 35, 'branch 6'], ['2015 / 11 / 22 ', 40,' branch 6 '],
['2015 / 11 / 23 ', 32,' branch 6 '], ['2015 / 11 / 24', 26, 'branch 6'], ['2015 / 11 / 25 ', 22,' branch 6 ']
]

import pyecharts.options as opts from pyecharts.charts import ThemeRiver datax = ['Branch 1', 'Branch 2', 'Branch 3', 'Branch 4', 'Branch 5', 'Branch 6'] datay = [ ['2015/11/08', 10, 'Branch 1'], ['2015/11/09', 15, 'Branch 1'], ['2015/11/10', 35, 'Branch 1'], ['2015/11/14', 7, 'Branch 1'], ['2015/11/15', 2, 'Branch 1'], ['2015/11/16', 17, 'Branch 1'], ['2015/11/17', 33, 'Branch 1'], ['2015/11/18', 40, 'Branch 1'], ['2015/11/19', 32, 'Branch 1'], ['2015/11/20', 26, 'Branch 1'], ['2015/11/21', 35, 'Branch 1'], ['2015/11/22', 40, 'Branch 1'], ['2015/11/23', 32, 'Branch 1'], ['2015/11/24', 26, 'Branch 1'], ['2015/11/25', 22, 'Branch 1'], ['2015/11/08', 35, 'Branch 2'], ['2015/11/09', 36, 'Branch 2'], ['2015/11/10', 37, 'Branch 2'], ['2015/11/11', 22, 'Branch 2'], ['2015/11/12', 24, 'Branch 2'], ['2015/11/13', 26, 'Branch 2'], ['2015/11/14', 34, 'Branch 2'], ['2015/11/15', 21, 'Branch 2'], ['2015/11/16', 18, 'Branch 2'], ['2015/11/17', 45, 'Branch 2'], ['2015/11/18', 32, 'Branch 2'], ['2015/11/19', 35, 'Branch 2'], ['2015/11/20', 30, 'Branch 2'], ['2015/11/21', 28, 'Branch 2'], ['2015/11/22', 27, 'Branch 2'], ['2015/11/23', 26, 'Branch 2'], ['2015/11/24', 15, 'Branch 2'], ['2015/11/25', 30, 'Branch 2'], ['2015/11/26', 35, 'Branch 2'], ['2015/11/27', 42, 'Branch 2'], ['2015/11/28', 42, 'Branch 2'], ['2015/11/08', 21, 'Branch 3'], ['2015/11/09', 25, 'Branch 3'], ['2015/11/10', 27, 'Branch 3'], ['2015/11/11', 23, 'Branch 3'], ['2015/11/12', 24, 'Branch 3'], ['2015/11/13', 21, 'Branch 3'], ['2015/11/14', 35, 'Branch 3'], ['2015/11/15', 39, 'Branch 3'], ['2015/11/16', 40, 'Branch 3'], ['2015/11/17', 36, 'Branch 3'], ['2015/11/18', 33, 'Branch 3'], ['2015/11/19', 43, 'Branch 3'], ['2015/11/20', 40, 'Branch 3'], ['2015/11/21', 34, 'Branch 3'], ['2015/11/22', 28, 'Branch 3'], ['2015/11/14', 7, 'Branch 4'], ['2015/11/15', 2, 'Branch 4'], ['2015/11/16', 17, 'Branch 4'], ['2015/11/17', 33, 'Branch 4'], ['2015/11/18', 40, 'Branch 4'], ['2015/11/19', 32, 'Branch 4'], ['2015/11/20', 26, 'Branch 4'], ['2015/11/21', 35, 'Branch 4'], ['2015/11/22', 40, 'Branch 4'], ['2015/11/23', 32, 'Branch 4'], ['2015/11/24', 26, 'Branch 4'], ['2015/11/25', 22, 'Branch 4'], ['2015/11/26', 16, 'Branch 4'], ['2015/11/27', 22, 'Branch 4'], ['2015/11/28', 10, 'Branch 4'], ['2015/11/08', 10, 'Branch 5'], ['2015/11/09', 15, 'Branch 5'], ['2015/11/10', 35, 'Branch 5'], ['2015/11/11', 38, 'Branch 5'], ['2015/11/12', 22, 'Branch 5'], ['2015/11/13', 16, 'Branch 5'], ['2015/11/14', 7, 'Branch 5'], ['2015/11/15', 2, 'Branch 5'], ['2015/11/16', 17, 'Branch 5'], ['2015/11/17', 33, 'Branch 5'], ['2015/11/18', 40, 'Branch 5'], ['2015/11/19', 32, 'Branch 5'], ['2015/11/20', 26, 'Branch 5'], ['2015/11/21', 35, 'Branch 5'], ['2015/11/22', 4, 'Branch 5'], ['2015/11/23', 32, 'Branch 5'], ['2015/11/24', 26, 'Branch 5'], ['2015/11/25', 22, 'Branch 5'], ['2015/11/26', 16, 'Branch 5'], ['2015/11/27', 22, 'Branch 5'], ['2015/11/28', 10, 'Branch 5'], ['2015/11/08', 10, 'Branch 6'], ['2015/11/09', 15, 'Branch 6'], ['2015/11/10', 35, 'Branch 6'], ['2015/11/11', 38, 'Branch 6'], ['2015/11/12', 22, 'Branch 6'], ['2015/11/13', 16, 'Branch 6'], ['2015/11/14', 7, 'Branch 6'], ['2015/11/15', 2, 'Branch 6'], ['2015/11/16', 17, 'Branch 6'], ['2015/11/17', 33, 'Branch 6'], ['2015/11/18', 4, 'Branch 6'], ['2015/11/19', 32, 'Branch 6'], ['2015/11/20', 26, 'Branch 6'], ['2015/11/21', 35, 'Branch 6'], ['2015/11/22', 40, 'Branch 6'], ['2015/11/23', 32, 'Branch 6'], ['2015/11/24', 26, 'Branch 6'], ['2015/11/25', 22, 'Branch 6'] ] themeRiver=( ThemeRiver(init_opts=opts.InitOpts(width="1600px", height="800px")) .add( series_name=datax, data=datay, singleaxis_opts=opts.SingleAxisOpts( pos_top="50", pos_bottom="50", type_="time" ), ) .set_global_opts( tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="line") ) ) themeRiver.render("theme_river.html")

12 June 2020, 05:02 | Views: 7106

Add new comment

For adding a comment, please log in
or create account

0 comments