[Python Learning]—Python Data Visualization (8)

[Python Learning]—Python Basic Grammar (8)

1. JSON data format

  • JSON is a lightweight data interaction format that can organize and encapsulate data according to the format specified by JSON.
  • JSON is essentially a string with a specific format
  • JSON is a data format that circulates in various programming languages ​​and is responsible for data transmission and interaction in different programming languages.
    Insert image description here

Mutual conversion of Python data and JSON data

Insert image description here
Insert image description here
Insert image description here
Insert image description here

2. pyecharts module

  • If you want to make a visual rendering, you can use the pyecharts module to complete it.
  • Echarts is a data visualization open sourced by Baidu. It has been recognized by many developers for its good interactivity and exquisite chart design. Python is an expressive language and is well suited for data processing. When data analysis meets data visualization, pyecharts was born.

Insert image description here
Insert image description here

What configuration options are there in pycharts

  • Global configuration options
  • Series configuration options
    Insert image description here
    Insert image description here
    Insert image description here
from pyecharts.charts import Line
from pyecharts.options import TitleOpts,LegendOpts,ToolboxOpts,VisualMapOpts

line=Line()
line.add_xaxis(["中国","英国","美国"])
line.add_yaxis("GDP",[30,20,10])

line.set_global_opts(
    title_opts=TitleOpts(title="GDP展示",pos_left="center", pos_bottom="1%"),
    legend_opts=LegendOpts(is_show=True),
    toolbox_opts=ToolboxOpts(is_show=True),
    visualmap_opts=VisualMapOpts(is_show=True)
)
line.render()

Summarize

Insert image description here

3. Map visualization

from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts

map=Map()
data=[
    ("北京市",99),
    ("上海市", 199),
    ("湖南省", 299),
    ("台湾省", 399),
    ("广东省", 499),
]
map.add("测试地图",data,"china")

#设置全局选项
map.set_global_opts(
    visualmap_opts=VisualMapOpts(
        is_show=True,
        is_piecewise=True,
        pieces=[
            {
    
    "min":1,"max":9,"label":"1-9","color":'#CCFFFF'},
{
    
    "min":10,"max":99,"label":"10-99","color":'pink'},
{
    
    "min":100,"max":500,"label":"100-500","color":'red'}]
    )
)
map.render()

Insert image description here

4. Dynamic bar chart

Insert image description here

from pyecharts.charts import Bar
from pyecharts.options import LabelOpts
bar=Bar()
bar.add_xaxis(["中国","美国","英国"])
bar.add_yaxis("GDP",[30,20,10],label_opts=LabelOpts(
    position="right"
))
#反转xy轴
bar.reversal_axis()
bar.render("基础柱状图.html")

Insert image description here

5. Timeline histogram

from pyecharts.charts import Bar,Timeline
from pyecharts.options import LabelOpts
from pyecharts.globals import ThemeType

bar1=Bar()
bar1.add_xaxis(["中国","美国","英国"])
bar1.add_yaxis("GDP",[30,20,10],label_opts=LabelOpts(
    position="right"
))
bar1.reversal_axis()

bar2=Bar()
bar2.add_xaxis(["中国","美国","英国"])
bar2.add_yaxis("GDP",[40,30,20],label_opts=LabelOpts(
    position="right"
))
bar2.reversal_axis()

bar3=Bar()
bar3.add_xaxis(["中国","美国","英国"])
bar3.add_yaxis("GDP",[50,60,40],label_opts=LabelOpts(
    position="right"
))
bar3.reversal_axis()

#构建时间线
timeline=Timeline()
{
    
    
        "theme":ThemeType.LIGHT
    }
timeline.add(bar1,"点1")
timeline.add(bar2,"点2")
timeline.add(bar3,"点3")
#设置自动播放
timeline.add_schema(
    play_interval=1000,
    is_timeline_show=True,
    is_auto_play=True,
    is_loop_play=True
)
timeline.render("基础时间线柱状图.html")

Insert image description here

6. Sort method of list


Insert image description here

Guess you like

Origin blog.csdn.net/m0_46374969/article/details/134103560