Data Visualization --pyecharts learn to build basic charts

Domestic recommends using the following image installation

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyecharts

 

When you are using python2.x, be sure to insert this code:

from __future__ import unicode_literals

When you are using python3.x, be sure to powder me!

 

 

 

Reference pyechart document: http://pyecharts.org/#/zh-cn/

The first step towards visualization, data analysis, not a thing.

 

 

[Use] the basic essentials are:

  1. Import Related charting package

  2. The basis of the chart, create a chart object

  3. Using add () method for setting the chart data input (use print_echarts_options () may be configured to output all items)

  4. Using the render () method to save the graph

 

 

Here is a list of method calls the old version, the new version, please refer to the official documentation

Such as the use

from pyecharts.charts import Bar 代替from pyecharts import Bar

 

We first create a set of data

// set the line name
columns = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
//设置数据
data1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
data2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]

Histogram -Bar

// Import histogram - Bar
 from pyecharts Import Bar
 // set the main title and subtitle histogram
bar = Bar ( " histogram " , " a year of precipitation and evaporation " )
 // add histogram data and configuration items
bar.add("降水量", columns, data1, mark_line=["average"], mark_point=["max", "min"])
bar.add ( " evaporation " , Columns, DATA2, mark_line = [ " Average " ], mark_point = [ " max " , " min " ])
 // generates a local file (default file .html)
bar.render()

Pie -Pie

// Import pie Pie
 from pyecharts Import Pie
 // set the main title and subtitle, centered title set, set the width to 900
PIE = Pie ( " pie chart " , " year precipitation and evaporation " , title_pos = ' Center ' , width = 900 )
 // added data, to set a coordinate position [25, 50 ], the above options colums cancel display
pie.add ( " precipitation " , Columns, DATAl, Center = [25,50], is_legend_show = False)
 // added data, to set a coordinate position [75, 50 ], colums option to cancel the above display, the display tag label
pie.add ( " evaporation " , Columns, DATA2, Center = [75,50], is_legend_show = False, is_label_show = True)
 // save the chart
pie.render()

FIG housing -Boxplot

// Import FIG box Boxplot for
 from pyecharts Import Boxplot for
Boxplot = Boxplot for ( " box plot " , " year precipitation and evaporation " )
X_AXIS = [ ' precipitation ' , ' evaporation ' ]
Y_AXIS = [DATAl, DATA2]
 // prepare_data method may be nested into the data [min, Ql, Median ( or Q2), Q3, max]
yaxis = boxplot.prepare_data(y_axis)       
boxplot.add ( " weather statistics " , X_AXIS, _yaxis)
boxplot.render()

 


Line chart -Line

from pyecharts import Line
Line = Line ( " line graph " , " year precipitation and evaporation " )
 // is_label_show is disposed above the data show whether
line.add("降水量", columns, data1, is_label_show=True)
line.add("蒸发量", columns, data2, is_label_show=True)
line.render()

Radar map -Rader

from pyecharts import Radar
Radar = Radar ( " radar chart " , " a year of precipitation and evaporation " )
 // Because the radar map incoming data was for the cube, so there need to do some processing
radar_data1 = [[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]]
radar_data2 = [[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3 ]]
 // set the maximum column, and more intuitive to a radar chart, where the maximum value provided month different
schema = [ 
    ("Jan", 5), ("Feb",10), ("Mar", 10),
    ("Apr", 50), ("May", 50), ("Jun", 200),
    ("Jul", 200), ("Aug", 200), ("Sep", 50),
    ("Oct", 50), ("Nov", 10), ("Dec", 5)
]
// incoming coordinates
radar.config(schema)
radar.add ( " precipitation " , radar_data1)
 // general default for the same color, where for convenience of distinction, it is necessary to set the color of the item
radar.add("蒸发量",radar_data2,item_color="#1C86EE")
radar.render()

Scatter -scatter

from pyecharts import Scatter
Scatter = The Scatter ( " Scatter " , " year precipitation and evaporation " )
 // xais_name abscissa name is set, since this display problem, but also to the y-axis and y-axis Title Set
scatter.add ( " precipitation and evaporation of the scatter distribution " , DATAl, DATA2, xaxis_name = " precipitation " , yaxis_name = " evaporation " ,
            yaxis_name_gap=40)
scatter.render()

 

 

Chart Layout Grid (1) --- separate table

from pyecharts Import the Grid
 // disposed fold line head position of FIG.
Line = Line ( " line graph " , " year precipitation and evaporation " , title_top = " 45% " )
line.add("降水量", columns, data1, is_label_show=True)
line.add("蒸发量", columns, data2, is_label_show=True)
Grid = the Grid ()
 // set the relative position of the two charts
grid.add(bar, grid_bottom="60%")
grid.add(line, grid_top="60%")
grid.render()

Chart Layout Grid (2) - combined form

from pyecharts import Overlap
overlap = Overlap()
bar = Bar ( " Histogram - combined line graph " , " year precipitation and evaporation " )
bar.add("降水量", columns, data1, mark_point=["max", "min"])
bar.add("蒸发量", columns, data2, mark_point=["max", "min"])
overlap.add(bar)
overlap.add(line)
overlap.render()

 

 

 

 

 

 

 

Reference Bowen:

https://www.jianshu.com/p/52dbe714d2f6

https://blog.csdn.net/weixin_42232219/article/details/90631442

https://www.jianshu.com/p/554d64470ec9

Guess you like

Origin www.cnblogs.com/xingnie/p/12363900.html