Python visualization library pandas_ Alive, do the dynamic chart at will

Time:2021-5-4

The text and pictures of this article are from the Internet, only for learning and communication, and do not have any commercial use. If you have any questions, please contact us in time.

The following article is a grade I farnast, written by F

Python visualization library pandas_ Alive, do the dynamic chart at will

 

preface

Recently, a similar visualization library “Pandas” has been found in Chinese_ “Alive” includes not only dynamic bar chart, but also dynamic curve chart, product, bubble chart, pie chart, map, etc.

The same is a few lines of code can complete the dynamic chart replacement.

GitHub address:

https://github.com/JackMcKew/pandas_alive

Use documentation:

https://jackmckew.github.io/pandas_alive/

The recommended installation version is 0.2.3,   Matplotlib version is 3.2.1.

At the same time, you need to install tqdm (display progress bar) and Descartes (place map related Library).

Otherwise, an error will be reported. It is estimated that the author’s request.txt does not contain these two libraries.

Well, after the successful installation, you can date the third-party library and directly select to load the local file.

import  pandas_alive as  pd 
import  pandas  
covid_df = pd.read_csv('data / covid19.csv',index_col = 0,parse_dates = [ 0 ])
covid_df.plot_animated(filename = 'examples / example-barh-chart.gif',n_visible = 15)

 

A GIF diagram is generated as follows.

Python visualization library pandas_ Alive, do the dynamic chart at will

 

At the beginning of learning this library, you can reduce the data, so that the time of generating GIF will be faster.

For example, in the next practice, basically only 20 days of data were selected.

Python visualization library pandas_ Alive, do the dynamic chart at will

 

For other diagrams, we can check the API description in the official document to understand.

Python visualization library pandas_ Alive, do the dynamic chart at will

 

Now let’s take a look at other dynamic chart replacement methods!

Dynamic bar chart

elec_ df = pd.read_ csv(“ data / Aus_ Elec_ Gen_ 1980_ 2018.csv”,index_ col = 0,parse_ Dates = [0], thousand yuan = ',')
elec_ df = elec_ df.iloc [:20,:] elec_ df.fillna(0).plot_ animated('examples / example-electricity- generation -australia.gif',period_ FMT =% Y ", title ='australian power generation sources 1980-2018 ')

 

Python visualization library pandas_ Alive, do the dynamic chart at will

 

02 dynamic histogram

covid_df = pd.read_csv('data / covid19.csv',index_col = 0,parse_dates = [ 0 ])
covid_ df.plot_ Animated (file name ='examples / example-barv-chart. GIF ', direction ='v', n_ visible = 15)

 

Python visualization library pandas_ Alive, do the dynamic chart at will

 

03 dynamic curve

covid_df = pd.read_csv('data / covid19.csv',index_col = 0,parse_dates = [ 0 ])
covid_df.diff()
fillna(0).plot_animated(filename = 'examples / example-line-chart.gif',kind = 'line',period_label = { 'x':  0.25,  'y':  0.9 })

 

Python visualization library pandas_ Alive, do the dynamic chart at will

 

04 dynamic area map

covid_df = pd.read_csv('data / covid19.csv',index_col = 0,parse_dates = [ 0 ])
covid_df.sum(axis = 1).fillna(0).plot_animated(filename = 'examples / example-bar-chart .gif',kind = 'bar',
        period_label = { 'x':  0.1,  'y':  0.9 },
        enable_progress_bar = True,steps_per_period = 2,interpolate_period = True,period_length = 200
)

 

Python visualization library pandas_ Alive, do the dynamic chart at will

 

05 dynamic scatter plot

max_temp_df = pd.read_csv(
    “ data / Newcastle_Australia_Max_Temps.csv”,
    parse_dates = { “ Timestamp”:[ “ Year”,  “ Month”,  “ Day” ]},
)
min_temp_df = pd.read_csv(
    “ data / Newcastle_Tustralia_T。,
    parse_dates = { “ Timestamp”:[ “ Year”,  “ Month”,  “ Day” ]},
)

max_temp_df = max_temp_df.iloc [:5000
,:] min_temp_df = min_temp_df.iloc [:5000

,:] merged_temp_df = pd。 merge_asof(max_temp_df,min_temp_df,on = “ Timestamp”)
merged_temp_df.index = pd.to_datetime(merged_temp_df [ “ Timestamp” ] .dt.strftime('%Y /%m /%d'))

keep_ Columns = ["minimum temperature (c)", "maximum temperature (c)" " 
merged_temp_df [keep_columns] .resample(“ Y”).mean()。plot_animated(filename = 'examples / example-scatter-chart.gif',kind = “ scatter”,
                                                                Title = "maximum and minimum temperatures Newcastle, Australia ')

 

Python visualization library pandas_ Alive, do the dynamic chart at will

 

06 dynamic pie chart

covid_df = pd.read_csv('data / covid19.csv',index_col = 0,parse_dates = [ 0 ])
covid_df.plot_animated(filename = 'examples / example-pie-chart.gif',kind = “ pie”,
                       rotationlabels = True,period_label = { 'x':  0,  'y':  0 })

 

Python visualization library pandas_ Alive, do the dynamic chart at will

 

07 dynamic bubble chart

multi_ index_ df = pd.read_ CSV ("data / multi. CSV", title = [0, 1], index_ col = 0)
multi_ index_ df.index = pd.to_ datetime(multi_ index_ DF. Index, dayfirst = true)

map_chart = multi_index_df.plot_animated(
    Type = bubble,
    The file name is "examples / example bubble chart. GIF",
    x_ data_ Label = longitude,
    y_ data_ Label = latitude,
    size_ data_ Label = case,
    color_ data_ Label = case,
    vmax = 5,steps_per_period = 3,interpolate_period = True,period_length = 500,
    dpi = 100
)

 

Python visualization library pandas_ Alive, do the dynamic chart at will

 

08 geospatial point chart

Imported geopandas
Import Panda_ alive
Import context 

GDF = geopandas.read_ File ('data / nsw-covid19-case by case postcode. Gpkg ')
gdf.index = gdf.postcode 
GDF = gdf.drop ('postcode ', axis = 1)

Results = GDF. Iloc [:,: 20] 
result [ 'geometry' ] = gdf.iloc [:,  -1:] [ 'geometry' ] 

map_chart = result.plot_animated(filename = 'examples / example-geo-point-chart .gif”,
                                 basemap_format = { 'source':contextily.providers.Stamen.Terrain})

 

Python visualization library pandas_ Alive, do the dynamic chart at will

 

09 general geographic chart

Imported geopandas
Import Panda_ alive
Import context 

GDF = geopandas.read_ File ('data / Italy - covid region. Gpkg ')
gdf.index = gdf.region 
GDF = GDF. Drop ('region ', axis = 1)

Results = GDF. Iloc [:,: 20] 
result [ 'geometry' ] = gdf.iloc [:,  -1:] [ 'geometry' ] 

map_chart = result.plot_animated(filename = 'examples / example-example-example-geo-polygon-chart.gif',
                                 basemap_format = { 'source':contextily.providers.Stamen.Terrain})

 

Python visualization library pandas_ Alive, do the dynamic chart at will