Use python to make beautiful dynamic images, how to use python to draw animated images

Hello everyone, this article will focus on using python to make beautiful dynamic images. How to use python to draw animated images is something that many people want to understand. To understand how to make dynamic data graphs with python, you need to understand the following things first.

Hello everyone

Regarding dynamic charts, I believe everyone has more or less come into contact with them. If you have a good code level, you can choose Matplotlib. Of course, you can also use the related functions of pyecharts. However, these tools focus on the production of charts, that is, for You need to convert the chart data yourself. The visualization gallery introduced today perfectly combines the Pandas data format, and is supplemented by the powerful functions of Matplotlib, making it much easier for us to create animated graphics .

Gallery introduction

This awesome visualization library is pandas_alive. Although the current number of stars on GitHub is not very high, I believe that with its powerful functions, it will be a matter of time before it stands out.

Project installation:
Just like the general Python library, you can install it directly using pip. One thing to note here is that because Matplotlib is used to create animations, you need to manually install Matplotlib's dependent tool imagemagick, which is an image processing tool. , interested students can check it out by themselves

Project functions:
This visualization gallery can support many chart types, including dynamic bar charts, dynamic curve charts, bubble charts, pie charts, maps, etc. These charts can almost meet our daily use.

Introduction to Cartography

Here we will take a brief look at how to make dynamic charts. The first is the dynamic bar chart. It is basically done with 4 lines of code. There are two lines of import.

import pandas_aliveimport pandas as pdcovid_df = pd.read_csv('covid19.csv', index_col=0, parse_dates=[0])covid_df.diff().fillna(0).plot_animated(filename='line_chart.gif',kind='line',period_label={'x':0.25,'y':0.9})

How about it? Isn’t it super convenient?

Let’s take a look at how to make other charts!

01 Dynamic Bar Chart

import pandas_aliveimport pandas as pdcovid_df = pd.read_csv('covid19.csv', index_col=0, parse_dates=[0])covid_df.plot_animated(filename='examples/perpendicular-example.gif',perpendicular_bar_func='mean')

02 Dynamic bar chart

import pandas_aliveimport pandas as pdcovid_df = pd.read_csv('covid19.csv', index_col=0, parse_dates=[0])covid_df.plot_animated(filename='examples/example-barv-chart.gif',orientation='v')

03 Dynamic curve graph

import pandas_aliveimport pandas as pdcovid_df = pd.read_csv('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

Guess you like

Origin blog.csdn.net/mynote/article/details/133531983