环形图

环形图其实是另一种饼图,使用的还是上面的 pie() 这个方法,这里只需要设置一下参数 wedgeprops 即可。

例子一:

import matplotlib.pyplot as plt

# 中文和负号的正常显示
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False # 数据
edu = [0.2515,0.3724,0.3336,0.0368,0.0057]
labels = ['中专','大专','本科','硕士','其他'] # 让本科学历离圆心远一点
explode = [0,0,0.1,0,0] # 将横、纵坐标轴标准化处理,保证饼图是一个正圆,否则为椭圆
plt.axes(aspect='equal') # 自定义颜色
colors=['#9999ff','#ff9999','#7777aa','#2442aa','#dd5555'] # 自定义颜色 # 绘制饼图
plt.pie(x=edu, # 绘图数据
explode = explode, # 突出显示大专人群
labels = labels, # 添加教育水平标签
colors = colors, # 设置饼图的自定义填充色
autopct = '%.1f%%', # 设置百分比的格式,这里保留一位小数
wedgeprops = {'width': 0.3, 'edgecolor':'green'}
) # 添加图标题
plt.title('xxx 公司员工教育水平分布') # 保存图形
plt.savefig('pie_demo1.png')

这个示例仅仅在前面示例的基础上增加了一个参数 wedgeprops 的设置,我们看下结果:

热力图

plt.imshow(x, cmap)
import numpy as np
import matplotlib.pyplot as plt x = np.random.rand(10, 10)
plt.imshow(x, cmap=plt.cm.hot) # 显示右边颜色条
plt.colorbar() plt.savefig('imshow_demo.png')

例子二

import numpy as np
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
from matplotlib.path import Path
from matplotlib.patches import PathPatch
delta = 0.025
x = y = np.arange(-3.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2 fig, ax = plt.subplots()
im = ax.imshow(Z, interpolation='bilinear', cmap=cm.RdYlGn,
origin='lower', extent=[-3, 3, -3, 3],
vmax=abs(Z).max(), vmin=-abs(Z).max()) plt.show()

例子3

import matplotlib.pyplot as plt
import numpy as np def func3(x, y):
return (1 - x / 2 + x**5 + y**3) * np.exp(-(x**2 + y**2)) # make these smaller to increase the resolution
dx, dy = 0.05, 0.05 x = np.arange(-3.0, 3.0, dx)
y = np.arange(-3.0, 3.0, dy)
X, Y = np.meshgrid(x, y) # when layering multiple images, the images need to have the same
# extent. This does not mean they need to have the same shape, but
# they both need to render to the same coordinate system determined by
# xmin, xmax, ymin, ymax. Note if you use different interpolations
# for the images their apparent extent could be different due to
# interpolation edge effects extent = np.min(x), np.max(x), np.min(y), np.max(y)
fig = plt.figure(frameon=False) Z1 = np.add.outer(range(8), range(8)) % 2 # chessboard
im1 = plt.imshow(Z1, cmap=plt.cm.gray, interpolation='nearest',
extent=extent) Z2 = func3(X, Y) im2 = plt.imshow(Z2, cmap=plt.cm.viridis, alpha=.9, interpolation='bilinear',
extent=extent) plt.show()

直方图

例子1

import matplotlib.pyplot as plt
import numpy as np
from matplotlib import colors
from matplotlib.ticker import PercentFormatter # Fixing random state for reproducibility
np.random.seed(19680801)
N_points = 100000
n_bins = 20 # Generate a normal distribution, center at x=0 and y=5
x = np.random.randn(N_points)
y = .4 * x + np.random.randn(100000) + 5 fig, axs = plt.subplots(1, 2, sharey=True, tight_layout=True) # We can set the number of bins with the `bins` kwarg
axs[0].hist(x, bins=n_bins)
axs[1].hist(y, bins=n_bins)

例子2

fig, axs = plt.subplots(1, 2, tight_layout=True)

# N is the count in each bin, bins is the lower-limit of the bin
N, bins, patches = axs[0].hist(x, bins=n_bins) # We'll color code by height, but you could use any scalar
fracs = N / N.max() # we need to normalize the data to 0..1 for the full range of the colormap
norm = colors.Normalize(fracs.min(), fracs.max()) # Now, we'll loop through our objects and set the color of each accordingly
for thisfrac, thispatch in zip(fracs, patches):
color = plt.cm.viridis(norm(thisfrac))
thispatch.set_facecolor(color) # We can also normalize our inputs by the total number of counts
axs[1].hist(x, bins=n_bins, density=True) # Now we format the y-axis to display percentage
axs[1].yaxis.set_major_formatter(PercentFormatter(xmax=1))

数据可视化基础专题(十三):Matplotlib 基础(五)常用图表(三)环形图、热力图、直方图的更多相关文章

  1. 数据可视化利器pyechart和matplotlib比较

    python中用作数据可视化的工具有多种,其中matplotlib最为基础.故在工具选择上,图形美观之外,操作方便即上乘. 本文着重说明常见图表用基础版matplotlib和改良版pyecharts作 ...

  2. 数据可视化:绘图库-Matplotlib

    为什么要绘图? 一个图表数据的直观分析,下面先看一组北京和上海上午十一点到十二点的气温变化数据: 数据: 这里我用一段代码生成北京和上海的一个小时内每分钟的温度如下: import random co ...

  3. 数据可视化(一)-Matplotlib简易入门

    本节的内容来源:https://www.dataquest.io/mission/10/plotting-basics 本节的数据来源:https://archive.ics.uci.edu/ml/d ...

  4. 数据可视化实例(十三): 发散型文本 (matplotlib,pandas)

    偏差 (Deviation) https://datawhalechina.github.io/pms50/#/chapter11/chapter11 发散型文本 (Diverging Texts) ...

  5. [原创.数据可视化系列之十三]idw反距离权重插值算法的javascript代码实现

    图形渲染中,idw反距离权重插值算法是一个应用非常广泛的方法,但是js实现的比较少,目前实现一个: //idw算法 //输入[[x:0,y:0,v:0],[x:0,y:0,v:0],[x:0,y:0, ...

  6. 数据可视化之powerBI技巧(十五)采悟:Power BI动态技巧:动态显示数据层级

    今天给大家分享一个动态显示数据层级的技巧,效果如下: 无论想按什么维度.什么顺序查看分析数据,只需要选择不同的切片器组合就行了. 方法如下:01 | 把数据聚合为分析需要的最细粒度 本文假设最细分析粒 ...

  7. 数据可视化之DAX篇(十五)Power BI按表筛选的思路

    https://zhuanlan.zhihu.com/p/121773967 ​数据分析就是筛选.分组.聚合的过程,关于筛选,可以按一个维度来筛选,也可以按多个维度筛选,还有种常见的方式是,利用几个特 ...

  8. 数据可视化之PowerQuery篇(十五)如何使用Power BI计算新客户数量?

    https://zhuanlan.zhihu.com/p/65119988 每个企业的经营活动都是围绕着客户而开展的,在服务好老客户的同时,不断开拓新客户是每个企业的经营目标之一. 开拓新客户必然要付 ...

  9. 4.5Python数据处理篇之Matplotlib系列(五)---plt.pie()饼状图

    目录 目录 前言 (一)简单的饼状图 (二)添加阴影和突出部分 (三)显示图例和数据标签: 目录 前言 饼状图需要导入的是: plt.pie(x, labels= ) (一)简单的饼状图 (1)说明: ...

  10. 关系网络数据可视化:3. 案例:公司职员关系图表 & 导演演员关系网络可视化

    1. 公司职员关系图表 节点和边界数据 节点是指每个节点本身的数据,代表公司职工的名称:属性(Country).分类(Category)和地区(Region,给每个节点定义的属性数据).文件必须是.c ...

随机推荐

  1. 别人开发三年30k,而我才12K,看完他面试前狂刷的面试题,我惊了

    朋友做Java开发三年多的时间了,在老东家勤勤恳恳工作了三年多,工资也就是从刚开始的8K涨到了12K,天天给我吐槽他的工资低.2019年中下旬开始就一直在各种地方找资源,刷面试题,想要“骑驴找马”,所 ...

  2. [转] 浅谈C++中的那些内存泄露

    点击阅读原文 尽管学过C语言.可是C++里面的一些基础还是不太懂,还须要再掌握. 对于内存泄露,我的个人理解就是程序在执行过程中,自己开辟了空间,用完这块空间后却没有释放. 今晚上我就犯了这种低级错误 ...

  3. mac App 破解之路六 studio 3t

    不想无限使用,直接破解到正版: 输入邮箱 名字之后 还有licence信息之后,处理函数是: this.text.getText() 很明显是你输入的licence.   然后交给父类okPress处 ...

  4. 让apk可调试

    一定是这个  <application android:debuggable="true"   不是这个玩意, debugaable, 也不是debugable这个玩意  

  5. 无法解析的外部符号 "public: virtual struct CRuntimeClass * _

    SetupPropertyPage.obj : error LNK2001: 无法解析的外部符号 "public: virtual struct CRuntimeClass * __this ...

  6. C++ 公有继承、保护继承和私有继承的对比

    在c++的继承控制中,有三种不同的控制权限,分别是public.protected和private.定义派生类时,若不显示加上这三个关键字,就会使用默认的方式,用struct定义的类是默认public ...

  7. 尚硅谷spring 事物管理

    接下来我们重点来学习spring中的事务管理 接下来我们通过代码来实现 spring实现事物我们采用aop的方式来实现 获得连接和手动设置事物相当于@before标注的前置通知,conn.commit ...

  8. java scoket Blocking 阻塞IO socket通信一

    package bhz.bio; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; p ...

  9. Python3-multiprocessing模块-多进程

    Python3中的multiprocessing模块是一个与threading模块类似,提供生成进程的API 多进程multiprocessing模块允许程序员充分利用给定机器上的多个CPU(处理器) ...

  10. springBoot--集成RocketMQ

    1.导入依赖 <dependency> <groupId>org.apache.rocketmq</groupId> <artifactId>sprin ...