Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of Python data visualization?

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what are the methods of Python data visualization". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Magical Altair

Before introducing the protagonist of this issue, I would like to give you a GIF.

Isn't it cool? What's even more amazing is that it takes less than 20 lines of code to complete such an interactive chart.

This picture is drawn with Altair, the visualization library of Python, and Altair can quickly develop various statistical visualization charts using powerful and concise visualization syntax. Users only need to provide links between data columns and coding channels, such as x-axis, y-axis, color, etc., and it will automatically deal with the rest of the drawing details.

In fact, there is much more Altair can do. You can go to the official website example gallery to watch it.

Install, configure, import Altair

If you are installing anaconda (I strongly recommend that you install this IDE), Altair is already built-in and does not need to be installed. But if you need an instance dataset, install vega_datasets:

Pip install vega_datasets

Then open the anaconda installation directory and open Navigation

Open JupyterLab

Create a new notebook and run the sample code, OK!

Altair graphic syntax

There are three basic methods for Chart: data, mark, and encode, which are used in the following format: alt.Chart (data). Mark_point (). Encode (

Encoding_1='column_1'

Encoding_2='column_2'

Etc.)

Data used internally by Data:Altair is stored in Dataframe format in Pandas, but it can be passed in in the following three ways:

Passed in DataFrame format of Pandas; in Data object; in url pointing to csv or json text

Mark: after defining the data, you need to select various interactive charts such as bar chart, line chart, area chart, scatter chart, histogram, map and so on.

Encoding: the encoding method defines the various attributes of the picture display, such as the position of each picture, the properties of the picture axis, and so on. This part is the most important, just remember the key ones.

Location channel: define location-related attributes:

X: X axis values y: y axis values row: pictures by row column: pictures by column

Channel description:

Color: marked point color opacity: marked point transparency shape: marked point shape size: marked point size

Channel domain information: text: text tag label: label

Data type:

Quantitative: abbreviation Q continuous data ordinal: abbreviation O discrete nominal: abbreviation N discrete disordered temporal: abbreviation T time series

Classification and aggregation: maximum, minimum, mean, summation, etc.

Interaction

In addition to drawing basic images, the power of Altair is that users can interact with the image, including panning, zooming, selecting a piece of data, and so on. After the code for drawing the picture, you can pan and zoom by calling the interactive () module.

Altair also provides a selection API for creating interactive images, and in terms of selection, we can make some more cool advanced features, such as the GIF shown at the beginning of this article, to count the selected data points and generate real-time histograms.

Import altair as alt

From vega_datasets import data

Source = data.cars ()

Brush = alt.selection (type='interval')

Points = alt.Chart (source). Mark_point (). Encode (add_selection (brush))

Bars = alt.Chart (source). Mark_bar (). Encode (yawned Origin bars), color='Origin:N', x='count (Origin): Q'). Transform_filter (brush)

The content of points & bars "what are the methods of Python data visualization" is introduced here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report