Python - 图表样式(Styling)

Python - 图表样式(Styling) 首页 / 数据科学入门教程 / Python - 图表样式(Styling)

通过使用用于制图的库中的一些适当方法,可以在python中创建的图表具有进一步的样式,在本课程中,将看到 执行注释,图示例和图表背景。无涯教程将继续使用上一章中的代码并对其进行修改,以将这些样式添加到图表中。

添加注释

很多时候,需要通过突出显示图表的特定位置来对图表进行注释。

import numpy as np 
from matplotlib import pyplot as plt 

x = np.arange(0,10) 
y = x ^ 2 
z = x ^ 3
t = x ^ 4 
# 标记轴和标题
plt.title("Graph Drawing") 
plt.xlabel("Time") 
plt.ylabel("Distance") 
plt.plot(x,y)

#Annotate
plt.annotate(xy=[2,1], s='Second Entry') 
plt.annotate(xy=[4,6], s='Third Entry') 

其输出如下-

链接:https://www.learnfk.comhttps://www.learnfk.com/python-data-science/python-chart-styling.html

来源:LearnFk无涯教程网

chartstyle1.png

添加图

有时无涯教程需要绘制带有多条线的图表,图示例的使用表示与每一行相关的含义,在下面的图表中,有3条带有相应图示例的线。

import numpy as np 
from matplotlib import pyplot as plt 

x = np.arange(0,10) 
y = x ^ 2 
z = x ^ 3
t = x ^ 4 
# 标记轴和标题
plt.title("Graph Drawing") 
plt.xlabel("Time") 
plt.ylabel("Distance") 
plt.plot(x,y)

#Annotate
plt.annotate(xy=[2,1], s='Second Entry') 
plt.annotate(xy=[4,6], s='Third Entry') 
# 添加图示例
plt.plot(x,z)
plt.plot(x,t)
plt.legend(['Race1', 'Race2','Race3'], loc=4) 

其输出如下-

链接:https://www.learnfk.comhttps://www.learnfk.com/python-data-science/python-chart-styling.html

来源:LearnFk无涯教程网

chartstyle2.png

图表风格

无涯教程可以使用样式包中的不同方法来修改图表的表示样式。

无涯教程网

import numpy as np 
from matplotlib import pyplot as plt 

x = np.arange(0,10) 
y = x ^ 2 
z = x ^ 3
t = x ^ 4 
# 标记轴和标题
plt.title("Graph Drawing") 
plt.xlabel("Time") 
plt.ylabel("Distance") 
plt.plot(x,y)

#Annotate
plt.annotate(xy=[2,1], s='Second Entry') 
plt.annotate(xy=[4,6], s='Third Entry') 
# 添加图示例
plt.plot(x,z)
plt.plot(x,t)
plt.legend(['Race1', 'Race2','Race3'], loc=4) 

#设置背景样式
plt.style.use('fast')
plt.plot(x,z)

其输出如下-

链接:https://www.learnfk.comhttps://www.learnfk.com/python-data-science/python-chart-styling.html

来源:LearnFk无涯教程网

chartstyle3.png

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

赵成的运维体系管理课 -〔赵成〕

软件测试52讲 -〔茹炳晟〕

MySQL实战45讲 -〔林晓斌〕

Kafka核心技术与实战 -〔胡夕〕

从0打造音视频直播系统 -〔李超〕

后端技术面试 38 讲 -〔李智慧〕

正则表达式入门课 -〔涂伟忠〕

WebAssembly入门课 -〔于航〕

结构学习力 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)