SoFunction
Updated on 2024-10-29

Python sample code for drawing stunning visual motion graphics

Today I would like to introduce you to a visualization module, the use of which you can draw a very stunning moving picture effect, then of course the first step is to install the module, through the pip command line to install:

pip install ipyvizzu

lit. have a small trial with a cow's knife

Let's start by simply using the module to draw a moving picture, importing the dataset using Pandas with the following code:

import pandas as pd
from ipyvizzu import Chart, Data, Config

data_frame = pd.read_csv("")

After importing the dataset is complete, I will first introduce the general steps to use the module, we instantiate the Data() object, and then the imported dataset will be placed in it, the code is as follows:

data = Data()
data.add_data_frame(data_frame)

We then instantiate the chart object Chart() and place the data containing the dataset in it:

chart = Chart()
(data)

Next, we began to draw the chart, you need to specify some of the attributes of the chart, such as histogram, that is, the X-axis Y-axis should be placed on what kind of data, the color selection is the default or need to be specified separately, as well as the title and so on:

(Config({"x": "Count", "y": "Sex", "label": "Count","title":"Passengers of the Titanic"}))

output:

Then we add the following code on top of that:

(Config({"x": ["Count","Survived"], "label": ["Count","Survived"], "color": "Survived"}))

output:

So the so-called moving pictures drawn by this module are actually an overlay of several static charts, so let's take a look at the complete case:

import pandas as pd
from ipyvizzu import Chart, Data, Config

data_frame = pd.read_csv("")
data = Data()
data.add_data_frame(data_frame)

chart = Chart()
(data)
(Config({"x": "Count", "y": "Sex", "label": "Count","title":"Passengers of the Titanic"}))
(Config({"x": ["Count","Survived"], "label": ["Count","Survived"], "color": "Survived"}))
(Config({"x": "Count", "y": ["Sex","Survived"]}))

output:

Moving graph shift between scatterplot and histograms

Because of the limited space, it is unlikely that I will be able to finish this knowledge point at once here, readers can go by themselves to theofficial websitelook sth up

Here I try to draw to draw a scatterplot and histogram between the moving picture shift, the first is to draw a scatterplot, the code is as follows:

import pandas as pd
from ipyvizzu import Chart, Data, Config, Style

data_frame = pd.read_csv("chart_types_eu.csv", dtype={"Year": str})
data = Data()
data.add_data_frame(data_frame)

chart = Chart()
(data)

(
    Config(
        {
            "channels": {
                "x": ["Joy factors", "Value 6 (+/-)"],
                "y": "Value 5 (+/-)",
                "color": "Joy factors",
                "size": "Value 2 (+)",
                "label": "Country_code",
            },
            "title": "Bubble Plot",
            "geometry": "circle",
        }
    )
)

output:

We use the title parameter to set the title, the size parameter to set the size of the scatter and the color parameter to set the color of the scatter, then we plot the histogram, the code is as follows:

(
    Config(
        {
            "channels": {
                "y": "Joy factors",
                "x": ["Value 2 (+)", "Country_code"],
                "label": None
            },
            "title": "Bar Chart",
            "geometry": "rectangle",
            "orientation": "vertical",
        }
    ),
    geometry={"delay": 0.7, "duration": 1},
)

output:

We then label the histogram with the following code:

(
    Config(
        {"channels": {"x": {"set": ["Value 2 (+)"]}, "label": {"set": ["Value 2 (+)"]}}}
    )
)

Let's take a general look at the results of the motion picture that came out, as shown below:

Whether it's static charts or dynamic, there are many other examples, check out this one of thelink (on a website)

Above is Python draw stunning visualization of moving pictures of the sample code in detail, more information about Python visualization of moving pictures please pay attention to my other related articles!