Today, I will introduce a visualization module to you. You can use it to draw amazing animation effects. Of course, the first step is to install this module. Like to remember to collect, follow, like.
Install from the pip
command line
pip install ipyvizzu
A small test
Note: The full version of the code, data, and technical exchange can be obtained at the end of the article.
Let's first simply use this module to draw a moving image and Pandas
import the data set. The code is as follows
import pandas as pd
from ipyvizzu import Chart, Data, Config
data_frame = pd.read_csv("titanic.csv")
After importing the dataset, let me introduce the general steps of using this module. We instantiate the Data()
object, and then place the imported dataset in it. The code is as follows
data = Data()
data.add_data_frame(data_frame)
Then we instantiate the chart object Chart()
and place the data set in data
it
chart = Chart()
chart.animate(data)
Next, we start to draw the chart. We need to specify some properties of the chart. For example, for a histogram, it is what data should be placed on the X-axis and Y-axis, whether the color selection is the default or needs to be specified, and the title, etc.
chart.animate(Config({
"x": "Count", "y": "Sex", "label": "Count","title":"Passengers of the Titanic"}))
output
Then we add the following code on this basis,
chart.animate(Config({
"x": ["Count","Survived"], "label": ["Count","Survived"], "color": "Survived"}))
output
Therefore, the so-called animation drawn by this module is actually the superposition of several static charts. Let's take a look at the complete case.
import pandas as pd
from ipyvizzu import Chart, Data, Config
data_frame = pd.read_csv("titanic.csv")
data = Data()
data.add_data_frame(data_frame)
chart = Chart()
chart.animate(data)
chart.animate(Config({
"x": "Count", "y": "Sex", "label": "Count","title":"Passengers of the Titanic"}))
chart.animate(Config({
"x": ["Count","Survived"], "label": ["Count","Survived"], "color": "Survived"}))
chart.animate(Config({
"x": "Count", "y": ["Sex","Survived"]}))
output
Animated transition between scatter plot and histogram
Due to the limited space, it is unlikely that the editor will finish this knowledge point at one time. Readers can check it out on the official website. github
The address is: https://github.com/vizzuhq/ipyvizzu/tree/main
Here, the editor tries to draw the transition between the scatter chart and the histogram. The first is to draw the scatter chart. 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()
chart.animate(data)
chart.animate(
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 title
set the title through the parameters, size
the size of color
the scatter points and the color of the scatter points are set by the parameters, then we will draw the histogram, the code is as follows
chart.animate(
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
Then we mark the histogram with the following code
chart.animate(
Config(
{
"channels": {
"x": {
"set": ["Value 2 (+)"]}, "label": {
"set": ["Value 2 (+)"]}}}
)
)
Let's take a look at the overall effect of the animation, as shown in the following figure
Whether it is static chart or dynamic, there are many other cases, you can refer to the following link for details: https://vizzuhq.github.io/ipyvizzu/examples/examples.html
recommended article
-
Li Hongyi's "Machine Learning" Mandarin Course (2022) is here
-
Someone made a Chinese version of Mr. Wu Enda's machine learning and deep learning
-
I'm addicted, and recently I gave the company a big visual screen (with source code)
-
So elegant, 4 Python automatic data analysis artifacts are really fragrant
Technology Exchange
Welcome to reprint, collect, like and support!
At present, a technical exchange group has been opened, and the group has more than 2,000 members . The best way to remark when adding is: source + interest direction, which is convenient to find like-minded friends
- Method 1. Send the following picture to WeChat, long press to identify, and reply in the background: add group;
- Method ②, add micro-signal: dkl88191 , note: from CSDN
- Method ③, WeChat search public account: Python learning and data mining , background reply: add group