Python: Chart pyecharts

A, Echarts Profile

Echarts is a visualization of Baidu open source data, with a good interactive, sophisticated graphic design, it has been recognized by many developers. The Python is an expressive language, it is suitable for data processing. When the data analysis encounter data visualization, pyecharts born.

Not compatible with sub-v0.5.x and V1, resulting in a lot of code is not reusable, the old version will no longer maintained.

1, characteristics

  • Simple API design, such as silky smooth, support for chained calls
  • 30+ kinds of common chart encompasses everything
  • Notebook supports mainstream environment, Jupyter Notebook and JupyterLab
  • It can be easily integrated into Flask, Sanic, Django Web framework and other mainstream
  • Highly flexible configuration options, you can easily match the beautiful chart
  • Detailed documentation and samples to help developers get started faster project
  • Up to 400 + map files, and supports native Baidu map, provide strong support for geographic data visualization

2. Related Resources:

Second, the use

Now we begin the formal use pycharts, where we directly use the official data:

1, bar -Bar

//导入柱状图-Bar
from pyecharts import Bar
//设置行名
columns = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "On Dec " ]
 // setting data 
DATAl = [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 ]
 // set the main title and the subtitle histogram 
bar = bar ( " histogram " , " year precipitation and evaporation " )
 // Add histogram data and configuration item 
bar.add ( " precipitation " , Columns, DATAl, 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 ()

Results are as follows:

Python data visualization using ultra-detailed guide of artifact --pyecharts!

A few simple lines of code data can be a very nice visual, but also dynamic, where Amway still have to look jupyter, pyecharts began in v0.1.9.2 version, calling on jupyter instance directly (for example, directly above the call bar ) can be represented charts directly, very convenient.

I counted on the current chart to support pyecharts about two dozen, then, we then used the data to generate the top of the charts a few examples of data mining:

2, 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 ], above the option to cancel the display colums 
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 label should 
pie.add ( " evaporation " , Columns, DATA2, Center = [75,50], is_legend_show = False, is_label_show =True)
 // save the chart 
pie.render ()

Python data visualization using ultra-detailed guide of artifact --pyecharts!

3, FIG box -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 ()

Python data visualization using ultra-detailed guide of artifact --pyecharts!

4, line -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 ( " precipitation " , Columns, DATAl, is_label_show = True) 
line.add ( " evaporation " , Columns, DATA2, is_label_show = True) 
line.render ()

Python data visualization using ultra-detailed guide of artifact --pyecharts!

 

5, the radar FIG -Rader

from pyecharts Import Radar 
Radar = Radar ( " radar chart " , " precipitation and evaporation of the year " )
 // 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 of the month differs in 
Schema = [ 
( " Jan " ,. 5), ( " On Feb " , 10), ( " -Mar ", 10),
("Apr", 50), ("May", 50), ("Jun", 200),
("Jul", 200), ("Aug", 200), ("Sep", 50),
("Oct", 50), ("Nov", 10), ("Dec", 5)
]
//传入坐标
radar.config(schema)
radar.add(""Precipitation, radar_data1)
 // general default for the same color, where for convenience of distinction, to set the color of item 
radar.add ( " evaporation " , radar_data2, item_color = " # 1C86EE " ) 
radar.render ()
image

6, scatter -scatter

from pyecharts Import The 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 Name set 
scatter.add ( " precipitation and evaporation of the scatter distribution " , DATAl, DATA2, xaxis_name = " precipitation " , yaxis_name = " evaporation " , 
 yaxis_name_gap = 40 ) 
scatter.render ()

Python data visualization using ultra-detailed guide of artifact --pyecharts!

7, graph layout Grid

Since the title of the chart belong to two different controls, so there must be heading the chart below Line location settings, otherwise there will be overlap title bug.

from pyecharts Import the Grid
 // set the position of the title line graph 
Line = Line ( " line graph " , " year precipitation and evaporation " , title_top = " 45% " ) 
line.add ( " precipitation " , Columns, DATAl , is_label_show = True) 
line.add ( " evaporation " , 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()

Python data visualization using ultra-detailed guide of artifact --pyecharts!

from pyecharts Import the Overlap 
Coverlap = the Overlap () 
bar = Bar ( " Histogram - combined line graph " , " year precipitation and evaporation " ) 
bar.add ( " precipitation " , Columns, DATAl, mark_point = [ " max " , " min " ]) 
bar.add ( " evaporation " , Columns, DATA2, mark_point = [ " max " , " min " ]) 
overlap.add (bar) 
Coverlap.add(line)
overlap.render()

Python data visualization using ultra-detailed guide of artifact --pyecharts!

to sum up

  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

pyecharts There are many fun 3D charts and maps charts, graphs Map personally feel is the most fun, you are interested can go pyecharts manual view, there is very convenient Chinese version.

Guess you like

Origin www.cnblogs.com/springsnow/p/12575607.html