search
HomeBackend DevelopmentPython TutorialFrom bronze to king, five Python libraries for advanced data visualization 2.0!

From bronze to king, five Python libraries for advanced data visualization 2.0!

The tools and libraries for data visualization have become extremely abundant. When you get used to one or more of them, you will do a great job, but if you become complacent, you will be disappointed. You'll miss out on new tools and libraries from Bronze to King. If you're still stuck with Matplotlib (which is amazing), Seaborn (which is also amazing), Pandas (basic, simple visualizations), and Bokeh, then you really need to stop and learn something new. For example, there are many amazing visualization libraries in Python that are already very general, such as these five:

Plotly

Cufflinks

Folium

Altair Vega

D3.js (Personally think it is the best choice since I also code in JS)

If you understand and use the libraries mentioned above, you are on the right track of evolution. They can help generate some impressive visualizations, and the syntax isn't difficult either. Generally speaking, I prefer Plotly Cufflinks and D3.js. Here are the details:

Plotly

Plotly is an open source, interactive and browser-based Python graphics library. It is possible to create interactive charts that can be used in dashboards or websites (you can save them as html files or static images). Plotly is based on plotly.js, which in turn is based on D3.js, so it is a high-level charting library. Like Bokeh, Plotly's strength is making interactive charts. There are more than 30 chart types, providing some in most Charts that are not in the library, such as contour charts, tree charts, scientific charts, statistical charts, 3D charts, financial charts, etc. The best thing about plotly is that it can be used in a Jupyter notebook or a standalone HTML page. You can also use it online on their website, but I prefer to use it offline, you can also save the visualization as an image, very easy to use and very useful.

– How to use Plotly in Jupyter Notebook (offline)

First, install the plotly library.

pip install plotly

Then open jupyter notebook and type:

from plotly import __version__ 
from plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot init_notebook_mode(connected = True)

The syntax is super simple! In Pandas, you use dataframe.plot(), here, you use dataframe.iplot(). This "i" changes the entire definition of visualization.

With just one line of code, I generated the scatter plot below. You can customize it according to your needs. Remember to specify the pattern tag, otherwise you'll get some lines.

From bronze to king, five Python libraries for advanced data visualization 2.0!

Please note that as the data increases, plotly will start to get stuck. So, I will use plotly only when the data points are less than 500K.

Related recommendations: "Python Video Tutorial"

Cufflinks

Cufflinks binds Plotly directly to the pandas data frame. This combination is amazing, combining the flexibility of Pandas with more efficiency than Plotly and an even simpler syntax than plotly. Using plotly's Python library, you can use a DataFrame's series and indices to describe the graph, but using Cufflinks allows you to plot it directly. As in the following example:

df = cf.datagen.lines()py.iplot([{  'x':df.index, 'y':df [col], 'name':col } 
<strong>for</strong> col <strong>in</strong> df.columns])

From bronze to king, five Python libraries for advanced data visualization 2.0!

##with plotly


df.iplot(kind= &#39;scatter&#39;)

From bronze to king, five Python libraries for advanced data visualization 2.0!

with cufflinks


Cufflinks make diagramming easier. You can even use Cufflinks to generate stunning 3D diagrams. I generated the 3D chart below with just a few lines of code.

From bronze to king, five Python libraries for advanced data visualization 2.0!

3D diagram generated with Cufflinks

You can always try it out in Jupyter Notebook.

– Quick Tip:

Set in configuration:

c.NotebookApp.iopub_data_rate_limit = 1.0e10

Import as follows:

import plotly.graph_objs as go
import plotly.plotly as py 
import cufflinks as cf 
from plotly.offline import iplot,init_notebook_mode 
cf.go_offline()
#Set global theme 
cf.set_config_file(world_readable = True,theme =&#39;pearl&#39;,offline = True )
init_notebook_mode()

Next, I will talk about another god library ——Viz library.

Folium

Folium is built on the data advantages of the Python ecosystem and the mapping advantages of the Leaflet.js library. You can manipulate the data in python and then visualize it in a Leaflet map via folium. Folium is a "magic library" for mapping spatial data. You can also use folium to generate heat maps and choropleth plots. Let's learn about folium:

A map is defined as a folium.Map object, and other folium objects can be added on top of the folium.

You can use different map layers for Folium rendered maps such as MapBox, OpenStreetMap and several others, you can check this github repository folder or this documentation page.

You can also choose different map projections. There are many projections to choose from.

Let’s generate a Choropleth map using the Geojson of Unemployment in the United States. Here's the snippet:

map = folium.Map([43, -100], zoom_start=4)
choropleth = folium.Choropleth( geo_data=us_states, data=state_data, 
columns=[&#39;State&#39;, &#39;Unemployment&#39;], key_on=&#39;feature.id&#39;, fill_color=&#39;YlGn&#39;, name=&#39;Unenployment&#39;, 
show=<strong>False</strong>,).add_to(m)
<em>
# 底层的GeoJson和StepColormap对象是可访问的
</em>
print(type(choropleth.geojson))
print(type(choropleth.color_scale))
folium.LayerControl(collapsed=<strong>False</strong>).add_to(m)
map.save(os.path.join(&#39;results&#39;, &#39;GeoChoro.html&#39;))
map

This is just a basic map, you can add markers, popups, and more. It can be the map generated by leaflet and folium below.

From bronze to king, five Python libraries for advanced data visualization 2.0!

Altair + Vega

Altair是一个声明性统计可视化库,基于Vega和Vega-Lite。

声明意味着只需要提供数据列与编码通道之间的链接,例如x轴,y轴,颜色等,其余的绘图细节它会自动处理。声明使Altair变得简单,友好和一致。使用Altair可以轻松设计出有效且美观的可视化代码。

Altair使您能够使用强大而简洁的可视化语法快速开发各种统计可视化图表。如果您使用的是Jupyter Notebook,则需要按以下方式安装它。它还包括一些示例vega数据集。

pip install -U altair vega_datasets notebook vega

Altair主要依赖Vega,为了使图表在屏幕上可见,你需要安装Vega,并且还需要为每个新会话运行此命令:

alt.renderers.enable(‘notebook’)

Altair中的数据是围绕Pandas Dataframe构建的。统计可视化最明显的特征是以整洁的Dataframes开始。您还可以将绘图另存为图像或在vega编辑器中打开它以获得更多选项。Altair可能不是最好的,但绝对值得一试。

下面这个例子,我使用了汽车数据集;

import altair as altfrom vega_datasets 
import datasource = data.cars()
brush = alt.selection(type=&#39;interval&#39;)
points = alt.Chart().mark_point().encode( x=&#39;Horsepower:Q&#39;, y=&#39;Miles_per_Gallon:Q&#39;, 
color=alt.condition(brush, &#39;Origin:N&#39;, alt.value(&#39;lightgray&#39;))).add_selection( brush)
bars = alt.Chart().mark_bar().encode( y=&#39;Origin:N&#39;, color=&#39;Origin:N&#39;, 
x=&#39;count(Origin):Q&#39;).transform_filter( brush)
alt.vconcat(points, bars, data=source)

From bronze to king, five Python libraries for advanced data visualization 2.0!

Altair和Vega生成的分散图和直方图

D3.js(数据驱动文档DDD)

D3.js是一个JavaScript库,根据数据操作文档。您可以使用HTML,SVG和CSS将数据变成活灵活现的图表。D3并不要求您将自己绑定到任何专有框架,因为现代浏览器拥有D3所需的一切,它还用于组合强大的可视化组件和数据驱动的DOM操作方法。

D3.js是目前市场上最好的数据可视化库。 您可以将它与python一起使用,也可以与R一起使用。最初,它可以与JavaScript一起使用,因为JS具有广泛的功能并且需要大量的学习和经验,但是如果你是JS专业人员则不需要犹豫。虽然 Python 和 R 使D3.js变得更简单,但只是一点点!总之D3.js是绝对不会错的上佳之选。

D3py有3个主要依赖项:

NumPy

Pandas

NetworkX

我建议你使用JavaScript或R,而不是python,因为版本已经过时,最后一次更新是在2016年。而且只是D3.js的一个瘦的python包装器。

R提供D3可视化接口。使用 r2d3 ,您可以将数据从R绑定到D3可视化。使用 r2d3 创建的D3可视化就像RStudio,R Markdown文档和Shiny应用程序中的R图一样工作。您可以按如下方式从CRAN 安装 r2d3 软件包:

install.packages(“r2d3”)

你可以做一些惊人的可视化,例如下面这几个:

From bronze to king, five Python libraries for advanced data visualization 2.0!

Sequences Sunburst — Kerry Rodden’s Block (Source)

From bronze to king, five Python libraries for advanced data visualization 2.0!

The above is the detailed content of From bronze to king, five Python libraries for advanced data visualization 2.0!. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:简书. If there is any infringement, please contact admin@php.cn delete
Python: Games, GUIs, and MorePython: Games, GUIs, and MoreApr 13, 2025 am 12:14 AM

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

Python vs. C  : Applications and Use Cases ComparedPython vs. C : Applications and Use Cases ComparedApr 12, 2025 am 12:01 AM

Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

The 2-Hour Python Plan: A Realistic ApproachThe 2-Hour Python Plan: A Realistic ApproachApr 11, 2025 am 12:04 AM

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python: Exploring Its Primary ApplicationsPython: Exploring Its Primary ApplicationsApr 10, 2025 am 09:41 AM

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

How Much Python Can You Learn in 2 Hours?How Much Python Can You Learn in 2 Hours?Apr 09, 2025 pm 04:33 PM

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

How to teach computer novice programming basics in project and problem-driven methods within 10 hours?How to teach computer novice programming basics in project and problem-driven methods within 10 hours?Apr 02, 2025 am 07:18 AM

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading?How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading?Apr 02, 2025 am 07:15 AM

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

What should I do if the '__builtin__' module is not found when loading the Pickle file in Python 3.6?What should I do if the '__builtin__' module is not found when loading the Pickle file in Python 3.6?Apr 02, 2025 am 07:12 AM

Error loading Pickle file in Python 3.6 environment: ModuleNotFoundError:Nomodulenamed...

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools