Skip to Content
Python数据科学手册
book

Python数据科学手册

by Jake VanderPlas
January 2018
Intermediate to advanced
470 pages
13h 23m
Chinese
Posts & Telecom Press
Content preview from Python数据科学手册
248
|
第
4
章
4.13
 
Matplotlib
自定义
:
配置文件与样式表
Matplotlib
的默认图形设置经常被用户诟病。虽然
Matplotlib 2.0
版本已经有大幅改善,但
是掌握自定义配置的方法可以让我们打造自己的艺术风格。
首先简单浏览一下
Matplotlib
的运行时配置(
runtime configuration
,rc)功能的介绍,然后
再看看新式的
样式表
(
stylesheets
)特性,里面包含了许多漂亮的默认配置功能。
4.13.1
 手动配置图形
通过本章的介绍,我们已经知道如何修改单个图形配置,使得最终图形比原来的图形更好
看。可以为每个单独的图形进行个性化设置。举个例子,看看由下面这个土到掉渣的默认
配置生成的频次直方图(如图
4-81
所示):
In[1]: import matplotlib.pyplot as plt
plt.style.use('classic')
import numpy as np
%matplotlib inline
In[2]: x = np.random.randn(1000)
plt.hist(x);
图 4-81:Matplotlib 默认配置的频次直方图
通过手动调整,可以让它成为美图,最终效果如图
4-82
所示:
In[3]: # 用灰色背景
ax = plt.axes(axisbg='#E6E6E6')
ax.set_axisbelow(True)
# 画上白色的网格线
plt.grid(color='w', linestyle='solid') ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

流畅的Python

流畅的Python

Luciano Ramalho
Python数据分析基础

Python数据分析基础

Clinton W. Brownley
Python数据处理

Python数据处理

Jacqueline Kazil, Katharine Jarmul

Publisher Resources

ISBN: 9787115475893