search
HomeBackend DevelopmentPython TutorialWhat are the commonly used Python data visualization libraries?

What are the commonly used Python data visualization libraries?

What library would you use for data visualization in Python?

Today I will share with you a powerful member of the Python data visualization library-Altair!

It is very simple, friendly, and built on the powerful Vega-Lite JSON specification. We only need short code to generate beautiful and effective visualizations.

What is Altair

Altair is a statistical visualization Python library that currently has more than 3,000 stars on GitHub.

With Altair, we can focus more energy and time on understanding the data itself and its meaning, and be freed from the complex data visualization process.

Simply put, Altair is a visual grammar and a declarative language for creating, saving and sharing interactive visual designs. It can use JSON format to describe the visual appearance and interaction process, and generate network-based image.

Let’s take a look at the visualization effects made using Altair!

What are the commonly used Python data visualization libraries?

What are the commonly used Python data visualization libraries?

What are the commonly used Python data visualization libraries?

What are the commonly used Python data visualization libraries?

What are the commonly used Python data visualization libraries?

#Altair's advantages

Altair can comprehensively understand, understand and analyze data through aggregation, data transformation, data interaction, graphic composite and other methods. These processes can help us increase our understanding of the data itself and its meaning, and cultivate intuitive data analysis thinking.

In general, the characteristics of Altair include the following aspects.

    Declarative Python API based on graphical syntax.
  • Generate Altair's Python code based on Vega-Lite's JSON syntax rules.
  • Show the statistical visualization process in the started Jupyter Notebook, JupyterLab and nteract.
  • You can export the visualization work as a picture in PNG/SVG format, a web page in HTML format that can be run independently, or you can view the running effect in the online Vega-Lite editor.
In Altair, the dataset used should be loaded in a "clean format". DataFrame in Pandas is one of the main data structures used by Altair. Altair has a good loading effect on Pandas DataFrame, and the loading method is simple and efficient. For example, use Pandas to read an Excel data set, and use Altair to load the implementation code of Pandas return values, as shown below:

import altair as alt
import pandas as pd
data = pd.read_excel( "Index_Chart_Altair.xlsx", sheet_name="Sales", parse_dates=["Year"] )
alt.Chart( data )

Quick test - make a bar chart

Altair places great emphasis on variables Differentiation and combination of types. The value of a variable is data, and there are differences. It can be expressed in the form of numerical values, strings, dates, etc. Variables are storage containers for data, and data are the contents of the storage units of variables.

On the other hand, from the perspective of statistical sampling, the variable is the population and the data is the sample. Samples need to be used to study and analyze the population. Statistical graphs can be generated by combining different variable types with each other to provide a more intuitive understanding of the data.

According to the combination of different variable types, the combination of variable types can be divided into the following types.

    Nominal variable Quantitative variable.
  • Time type variable Quantity type variable.
  • Time variable Nominal variable.
  • Quantitative variable Quantitative variable.
Among them, the time variable is a special type of quantitative variable. The time variable can be set as a nominal variable (N) or an ordinal variable (O) to realize the time variable. discretization to form a combination with quantitative variables.

Here we will explain one of the nominal variables and quantitative variables.

If you map quantitative variables to the x-axis, map nominal variables to the y-axis, and still use columns as the encoding style (marking style) of the data, you can draw a bar chart. Bar charts can better use changes in length to compare the gap in profit from merchandise sales, as shown in the figure below.

What are the commonly used Python data visualization libraries?

Compared with the implementation code of the column chart, the changes in the implementation code of the bar chart are as follows.

chart = alt.Chart(df).mark_bar().encode(x="profit:Q",y="product:N")

Complex graphs are also very simple

Let’s demonstrate the average monthly rainfall in different years by partition!

我们可以使用面积图描述西雅图从2012 年到2015 年的每个月的平均降雨量统计情况。接下来,进一步拆分平均降雨量,以年份为分区标准,使用阶梯图将具体年份的每月平均降雨量分区展示,如下图所示。

What are the commonly used Python data visualization libraries?

核心的实现代码如下所示。

…
chart = alt.Chart(df).mark_area(
color="lightblue",
interpolate="step",
line=True,
opacity=0.8
).encode(
alt.X("month(date):T",
axis=alt.Axis(format="%b",
formatType="time",
labelAngle=-15,
labelBaseline="top",
labelPadding=5,
title="month")),
y="mean(precipitation):Q",
facet=alt.Facet("year(date):Q",
columns=4,
header=alt.Header(
labelColor="red",
labelFontSize=15,
title="Seattle Monthly Precipitation from 2012 to 2015",
titleFont="Calibri",
titleFontSize=25,
titlePadding=15)
)
0)
…

在类alt.X()中,使用month 提取时间型变量date 的月份,映射在位置通道x轴上,使用汇总函数mean()计算平均降雨量,使用折线作为编码数据的标记样式。

在实例方法encode()中,使用子区通道facet 设置分区,使用year 提取时间型变量date 的年份,作为拆分从2012 年到2015 年每个月的平均降雨量的分区标准,从而将每年的不同月份的平均降雨量分别显示在对应的子区上。使用关键字参数columns设置子区的列数,使用关键字参数header 设置子区序号和子区标题的相关文本内容。

具体而言,使用Header 架构包装器设置文本内容,也就是使用类alt.Header()的关键字参数完成文本内容的设置任务,关键字参数的含义如下所示。

  • labelColor:序号标签颜色。
  • labelFontSize:序号标签大小。
  • title:子区标题。
  • titleFont:子区字体。
  • titleFontSize:子区字体大小。
  • titlePadding:子区标题与序号标签的留白距离。

The above is the detailed content of What are the commonly used Python data visualization libraries?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:51CTO.COM. If there is any infringement, please contact admin@php.cn delete
详细讲解Python之Seaborn(数据可视化)详细讲解Python之Seaborn(数据可视化)Apr 21, 2022 pm 06:08 PM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于Seaborn的相关问题,包括了数据可视化处理的散点图、折线图、条形图等等内容,下面一起来看一下,希望对大家有帮助。

详细了解Python进程池与进程锁详细了解Python进程池与进程锁May 10, 2022 pm 06:11 PM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于进程池与进程锁的相关问题,包括进程池的创建模块,进程池函数等等内容,下面一起来看一下,希望对大家有帮助。

Python自动化实践之筛选简历Python自动化实践之筛选简历Jun 07, 2022 pm 06:59 PM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于简历筛选的相关问题,包括了定义 ReadDoc 类用以读取 word 文件以及定义 search_word 函数用以筛选的相关内容,下面一起来看一下,希望对大家有帮助。

归纳总结Python标准库归纳总结Python标准库May 03, 2022 am 09:00 AM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于标准库总结的相关问题,下面一起来看一下,希望对大家有帮助。

分享10款高效的VSCode插件,总有一款能够惊艳到你!!分享10款高效的VSCode插件,总有一款能够惊艳到你!!Mar 09, 2021 am 10:15 AM

VS Code的确是一款非常热门、有强大用户基础的一款开发工具。本文给大家介绍一下10款高效、好用的插件,能够让原本单薄的VS Code如虎添翼,开发效率顿时提升到一个新的阶段。

python中文是什么意思python中文是什么意思Jun 24, 2019 pm 02:22 PM

pythn的中文意思是巨蟒、蟒蛇。1989年圣诞节期间,Guido van Rossum在家闲的没事干,为了跟朋友庆祝圣诞节,决定发明一种全新的脚本语言。他很喜欢一个肥皂剧叫Monty Python,所以便把这门语言叫做python。

Python数据类型详解之字符串、数字Python数据类型详解之字符串、数字Apr 27, 2022 pm 07:27 PM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于数据类型之字符串、数字的相关问题,下面一起来看一下,希望对大家有帮助。

详细介绍python的numpy模块详细介绍python的numpy模块May 19, 2022 am 11:43 AM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于numpy模块的相关问题,Numpy是Numerical Python extensions的缩写,字面意思是Python数值计算扩展,下面一起来看一下,希望对大家有帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment