加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python+matplotlib绘制饼图散点图实例代码

发布时间:2020-12-17 07:32:19 所属栏目:Python 来源:网络整理
导读:本文是从matplotlib官网上摘录下来的一个实例,实现的功能是Python+matplotlib绘制自定义饼图作为散点图的标记,具体如下。 首先看下演示效果 实例代码: import numpy as npimport matplotlib.pyplot as plt# first define the ratiosr1 = 0.2 # 20%r2 = r1

本文是从matplotlib官网上摘录下来的一个实例,实现的功能是Python+matplotlib绘制自定义饼图作为散点图的标记,具体如下。

首先看下演示效果

实例代码:

import numpy as np
import matplotlib.pyplot as plt

# first define the ratios
r1 = 0.2    # 20%
r2 = r1 + 0.4 # 40%

# define some sizes of the scatter marker
sizes = np.array([60,80,120])

# calculate the points of the first pie marker
#
# these are just the origin (0,0) +
# some points on a circle cos,sin
x = [0] + np.cos(np.linspace(0,2 * np.pi * r1,10)).tolist()
y = [0] + np.sin(np.linspace(0,10)).tolist()
xy1 = list(zip(x,y))
s1 = np.max(xy1)

x = [0] + np.cos(np.linspace(2 * np.pi * r1,2 * np.pi * r2,10)).tolist()
y = [0] + np.sin(np.linspace(2 * np.pi * r1,10)).tolist()
xy2 = list(zip(x,y))
s2 = np.max(xy2)

x = [0] + np.cos(np.linspace(2 * np.pi * r2,2 * np.pi,10)).tolist()
y = [0] + np.sin(np.linspace(2 * np.pi * r2,10)).tolist()
xy3 = list(zip(x,y))
s3 = np.max(xy3)

fig,ax = plt.subplots()
ax.scatter(range(3),range(3),marker=(xy1,0),s=s1 ** 2 * sizes,facecolor='blue')
ax.scatter(range(3),marker=(xy2,s=s2 ** 2 * sizes,facecolor='green')
ax.scatter(range(3),marker=(xy3,s=s3 ** 2 * sizes,facecolor='red')

plt.show()

总结

以上就是本文关于python+matplotlib绘制饼图散点图实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

您可能感兴趣的文章:

  • python+matplotlib实现动态绘制图片实例代码(交互式绘图)
  • Python+matplotlib绘制不同大小和颜色散点图实例
  • Python使用matplotlib填充图形指定区域代码示例
  • python+matplotlib实现礼盒柱状图实例代码
  • Python+matplotlib实现填充螺旋实例
  • python+matplotlib实现鼠标移动三角形高亮及索引显示
  • python+matplotlib演示电偶极子实例代码
  • Python+matplotlib实现华丽的文本框演示代码

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读