python绘制图像

news2024/9/27 17:34:22

柱状图

import os

# 输入想要存储图像的路径
os.chdir('D:')

import matplotlib.pyplot as plt
import numpy as np
# 改变绘图风格
import seaborn as sns

sns.set(color_codes=True)

cell = ['gen7', 'xgspon', '3081GB', 'vettel', 'totalplay', 'other']
pvalue = [21, 20, 18, 13, 7, 34]

width = 0.60
index = np.arange(len(cell))
p1 = np.arange(0, len(cell), 0.01)
p2 = 0.05 + p1 * 0

q1 = np.arange(0, len(cell), 0.01)
q2 = 0.1 + p1 * 0

figsize = (10, 8)  # 调整绘制图片的比例
plt.plot(p1, p2, color='red', label='5% significance level')  # 绘制直线
plt.plot(q1, q2, color='yellow', label='10% significance level')  # 绘制直线
# 若是不想显示直线,可以直接将上面两行注释掉
#plt.bar(index, pvalue, width, color="#87CEFA")  # 绘制柱状图
plt.bar(index, pvalue, width,color=['y','g','b', 'c', 'm', 'r','k','gold'])
# plt.xlabel('cell type') #x轴
plt.ylabel('bug num')  # y轴
plt.title('project and bug num show')  # 图像的名称
plt.xticks(index, cell, fontsize=10)  # 将横坐标用cell替换,fontsize用来调整字体的大小
plt.legend()  # 显示label
plt.show()
plt.savefig('test.png', dpi=400)  # 保存图像,dpi可以调整图像的像素大小

效果预览

import os

# 输入想要存储图像的路径
os.chdir('D:')

import matplotlib.pyplot as plt
import numpy as np
# 改变绘图风格
import seaborn as sns

sns.set(color_codes=True)

cell = ['Viettel', 'LLA', 'Telmex', 'gen7', 'Claro', 'RDS&1835GRF']
pvalue = [43, 32, 55, 21, 28, 15]

width = 0.60
index = np.arange(len(cell))
p1 = np.arange(0, len(cell), 0.01)
p2 = 0.05 + p1 * 0

q1 = np.arange(0, len(cell), 0.01)
q2 = 0.1 + p1 * 0

figsize = (10, 8)  # 调整绘制图片的比例
plt.plot(p1, p2, color='red', label='5% significance level')  # 绘制直线
plt.plot(q1, q2, color='yellow', label='10% significance level')  # 绘制直线
# 若是不想显示直线,可以直接将上面两行注释掉
#plt.bar(index, pvalue, width, color="#87CEFA")  # 绘制柱状图
plt.bar(index, pvalue, width,color=['y','g','b', 'c', 'm', 'r','k','gold'])
# plt.xlabel('cell type') #x轴
plt.ylabel('bug num')  # y轴
plt.title('project and occpuy time show')  # 图像的名称
plt.xticks(index, cell, fontsize=10)  # 将横坐标用cell替换,fontsize用来调整字体的大小
plt.legend()  # 显示label
plt.show()
plt.savefig('test.png', dpi=400)  # 保存图像,dpi可以调整图像的像素大小

import os

# 输入想要存储图像的路径
os.chdir('D:')

import matplotlib.pyplot as plt
import numpy as np
# 改变绘图风格
import seaborn as sns

sns.set(color_codes=True)

cell = ['Viettel', 'LLA', 'Telmex', 'gen7', 'Claro', 'Totalplay_3081']
pvalue = [23, 32, 35, 28, 15, 20]

width = 0.60
index = np.arange(len(cell))
p1 = np.arange(0, len(cell), 0.01)
p2 = 0.05 + p1 * 0

q1 = np.arange(0, len(cell), 0.01)
q2 = 0.1 + p1 * 0

figsize = (10, 8)  # 调整绘制图片的比例
plt.plot(p1, p2, color='red', label='5% significance level')  # 绘制直线
plt.plot(q1, q2, color='yellow', label='10% significance level')  # 绘制直线
# 若是不想显示直线,可以直接将上面两行注释掉
#plt.bar(index, pvalue, width, color="#87CEFA")  # 绘制柱状图
plt.bar(index, pvalue, width,color=['y','g','b', 'c', 'm', 'r','k','gold'])
# plt.xlabel('cell type') #x轴
plt.ylabel('bug num')  # y轴
plt.title('project and occpuy time show')  # 图像的名称
plt.xticks(index, cell, fontsize=10)  # 将横坐标用cell替换,fontsize用来调整字体的大小
plt.legend()  # 显示label
plt.show()
plt.savefig('test.png', dpi=400)  # 保存图像,dpi可以调整图像的像素大小

饼图

import matplotlib.pyplot as plt
from matplotlib.patches import ConnectionPatch
import numpy as np
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 5))
fig.subplots_adjust(wspace=0)
ratios = [.27, .56, .17]
labels = ['Factory', 'Bug', 'CE']
explode = [0.1, 0, 0]
angle = -180 * ratios[0]
ax1.pie(ratios, autopct='%1.1f%%', startangle=angle,
        labels=labels, explode=explode)
xpos = 0
bottom = 0
ratios = [.30, .50, .20]
width = .2
colors = [[.1, .3, .5], [.1, .3, .3], [.1, .3, .7], [.1, .3, .9]]
num1 = "factory tool"
num2 = "product SOP"
num3 = "maintence"
num = ["factory tool","product SOP","maintence"]
print(num[1])
for j in range(len(ratios)):
    height = ratios[j]
    ax2.bar(xpos, height, width, bottom=bottom, color=colors[j])
    ypos = bottom + ax2.patches[j].get_height() / 2
    bottom += height
    ax2.text(xpos, ypos, num[j],
             ha='center')
ax2.set_title('list')
#ax2.legend(('50-65', 'Over 65', '35-49', 'Under 35'))
ax2.axis('off')
ax2.set_xlim(- 2.5 * width, 2.5 * width)

theta1, theta2 = ax1.patches[0].theta1, ax1.patches[0].theta2
center, r = ax1.patches[0].center, ax1.patches[0].r
bar_height = sum([item.get_height() for item in ax2.patches])
# draw top connecting line
x = r * np.cos(np.pi / 180 * theta2) + center[0]
y = r * np.sin(np.pi / 180 * theta2) + center[1]
con = ConnectionPatch(xyA=(-width / 2, bar_height), coordsA=ax2.transData,
                      xyB=(x, y), coordsB=ax1.transData)
con.set_color([0, 0, 0])
con.set_linewidth(4)
ax2.add_artist(con)
# draw bottom connecting line
x = r * np.cos(np.pi / 180 * theta1) + center[0]
y = r * np.sin(np.pi / 180 * theta1) + center[1]
con = ConnectionPatch(xyA=(-width / 2, 0), coordsA=ax2.transData,
                      xyB=(x, y), coordsB=ax1.transData)
con.set_color([0, 0, 0])
ax2.add_artist(con)
con.set_linewidth(4)
plt.show()
import matplotlib.pyplot as plt
from matplotlib.patches import ConnectionPatch
import numpy as np
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 5))
fig.subplots_adjust(wspace=0)
ratios = [.43, .45, .18]
labels = ['Telmex support', 'fixed Bug', 'write document']
explode = [0.1, 0, 0]
angle = -180 * ratios[0]
ax1.pie(ratios, autopct='%1.1f%%', startangle=angle,
        labels=labels, explode=explode)
xpos = 0
bottom = 0
ratios = [.30, .50, .20]
width = .2
colors = [[.1, .3, .5], [.1, .3, .3], [.1, .3, .7], [.1, .3, .9]]
num1 = "Documentation"
num2 = "Customer Field Test"
num3 = "identify the problem"
num = ["Documentation","Customer Field Test","identify the problem"]
print(num[1])
for j in range(len(ratios)):
    height = ratios[j]
    ax2.bar(xpos, height, width, bottom=bottom, color=colors[j])
    ypos = bottom + ax2.patches[j].get_height() / 2
    bottom += height
    ax2.text(xpos, ypos, num[j],
             ha='center')
ax2.set_title('list')
#ax2.legend(('50-65', 'Over 65', '35-49', 'Under 35'))
ax2.axis('off')
ax2.set_xlim(- 2.5 * width, 2.5 * width)

theta1, theta2 = ax1.patches[0].theta1, ax1.patches[0].theta2
center, r = ax1.patches[0].center, ax1.patches[0].r
bar_height = sum([item.get_height() for item in ax2.patches])
# draw top connecting line
x = r * np.cos(np.pi / 180 * theta2) + center[0]
y = r * np.sin(np.pi / 180 * theta2) + center[1]
con = ConnectionPatch(xyA=(-width / 2, bar_height), coordsA=ax2.transData,
                      xyB=(x, y), coordsB=ax1.transData)
con.set_color([0, 0, 0])
con.set_linewidth(4)
ax2.add_artist(con)
# draw bottom connecting line
x = r * np.cos(np.pi / 180 * theta1) + center[0]
y = r * np.sin(np.pi / 180 * theta1) + center[1]
con = ConnectionPatch(xyA=(-width / 2, 0), coordsA=ax2.transData,
                      xyB=(x, y), coordsB=ax1.transData)
con.set_color([0, 0, 0])
ax2.add_artist(con)
con.set_linewidth(4)
plt.show()

bug分布饼图

import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = 'simhei'
data = [16, 10, 9,4,4,15]
label = ['web issues', 'other(CWMP DHCP DNS FLASH VOIp VLAN)','olt issues','SDK issues','WAN/ipv6','wifi issues']
plt.pie(data, labels = label, autopct='%.2f%%')
plt.title('bug分布图')
plt.show()

雷达图

import numpy as np
import matplotlib.pyplot as plt
# 用于正常显示中文
plt.rcParams['font.sans-serif'] = 'SimHei'
#用于正常显示符号
plt.rcParams['axes.unicode_minus'] = False
 
# 使用ggplot的绘图风格,这个类似于美化了,可以通过plt.style.available查看可选值,你会发现其它的风格真的丑。。。
plt.style.use('ggplot')
 
# 构造数据
values = [2.6,2.1,3.4,3,4.1]
feature = ['个人能力','QC知识','解决问题能力','服务质量意识','团队精神']
 
# 设置每个数据点的显示位置,在雷达图上用角度表示
angles=np.linspace(0, 2*np.pi,len(values), endpoint=False)
 
# 拼接数据首尾,使图形中线条封闭
values=np.concatenate((values,[values[0]]))
angles=np.concatenate((angles,[angles[0]]))
 
# 绘图
fig=plt.figure()
# 设置为极坐标格式
ax = fig.add_subplot(111, polar=True)
# 绘制折线图
ax.plot(angles, values, 'o-', linewidth=2)
# 填充颜色
ax.fill(angles, values, alpha=0.25)
 
# 设置图标上的角度划分刻度,为每个数据点处添加标签
ax.set_thetagrids(angles * 180/np.pi, feature)
 
# 设置雷达图的范围
ax.set_ylim(0,5)
# 添加标题
plt.title('活动前后员工状态表现')
# 添加网格线
ax.grid(True)
 
plt.show()
import numpy as np
import matplotlib.pyplot as plt

# 用于正常显示中文
#plt.rcParams['font.family'] = ['sans-serif']#如果是windows系统请去掉这行注释
#plt.rcParams['font.sans-serif'] = ['SimHei']#如果是windows系统请去掉这行注释

plt.rcParams['font.sans-serif'] = 'SimHei'

# 用于正常显示符号
plt.rcParams['axes.unicode_minus'] = False

plt.style.use('ggplot')
# 使用ggplot的绘图风格
plt.style.use('ggplot')

# 各个属性值
feature = ['语文', '数学', '英语', '物理', '化学', '生物']
value = np.array([95, 96, 98, 85, 79, 85])

# 设置每个数据点的显示位置,在雷达图上用角度表示
angles = np.linspace(0, 2 * np.pi, len(feature), endpoint=False)
angles = np.concatenate((angles, [angles[0]]))
feature = np.concatenate((feature, [feature[0]]))
# 绘图
fig = plt.figure(facecolor='white')
subject_label = ['王康']
# 拼接数据首尾,使图形中线条封闭
values = np.concatenate((value, [value[0]]))
print(values)
# 设置为极坐标格式
ax = fig.add_subplot(111, polar=True)
# 绘制折线图
ax.plot(angles, values, 'o-', linewidth=1, label=subject_label[0])
# 填充颜色
ax.fill(angles, values, alpha=0.25)

# 设置图标上的角度划分刻度,为每个数据点处添加标签
ax.set_thetagrids(angles * 180 / np.pi, feature)

# 设置雷达图的范围
ax.set_ylim(0, 100)

# 添加标题
plt.title('不同学生成绩分布雷达图')
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=1, frameon=False)
# 添加网格线
ax.grid(True)
# 保存图片
# plt.savefig('雷达图.png')

plt.show()

import numpy as np
import matplotlib.pyplot as plt

# 用于正常显示中文
#plt.rcParams['font.family'] = ['sans-serif']#如果是windows系统请去掉这行注释
#plt.rcParams['font.sans-serif'] = ['SimHei']#如果是windows系统请去掉这行注释

plt.rcParams['font.sans-serif'] = 'SimHei'

# 用于正常显示符号
plt.rcParams['axes.unicode_minus'] = False

plt.style.use('ggplot')
# 使用ggplot的绘图风格
plt.style.use('ggplot')

# 各个属性值
feature = ['个人能力', '网通知识', '解决问题能力', '服务质量意识', '团队精神', '沟通能力']
value = np.array([80, 76, 86, 90, 79, 70])

# 设置每个数据点的显示位置,在雷达图上用角度表示
angles = np.linspace(0, 2 * np.pi, len(feature), endpoint=False)
angles = np.concatenate((angles, [angles[0]]))
feature = np.concatenate((feature, [feature[0]]))
# 绘图
fig = plt.figure(facecolor='white')
subject_label = ['李勇']
# 拼接数据首尾,使图形中线条封闭
values = np.concatenate((value, [value[0]]))
print(values)
# 设置为极坐标格式
ax = fig.add_subplot(111, polar=True)
# 绘制折线图
ax.plot(angles, values, 'o-', linewidth=1, label=subject_label[0])
# 填充颜色
ax.fill(angles, values, alpha=0.25)

# 设置图标上的角度划分刻度,为每个数据点处添加标签
ax.set_thetagrids(angles * 180 / np.pi, feature)

# 设置雷达图的范围
ax.set_ylim(0, 100)

# 添加标题
plt.title('能力分布图')
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=1, frameon=False)
# 添加网格线
ax.grid(True)
# 保存图片
# plt.savefig('雷达图.png')

plt.show()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2170585.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

​​XrayGLM原理与部署

接上一篇:VisualGLM-6B——原理与部署-CSDN博客 XrayGLM技术背景与原理 XrayGLM 是一种基于 VisualGLM-6B 微调开发的多模态医学影像诊断模型,专门用于处理医学影像(如 X 光胸片)的自动诊断和报告生成任务。该模型旨在为中文医学…

第8章_索引的创建与设计原则

1. 索引的声明与使用 1.1 索引的分类 MySQL的索引包括普通索引、唯一性索引、全文索引、单列索引、多列索引和空间索引等。 从 功能逻辑 上说,索引主要有 4 种,分别是普通索引、唯一索引、主键索引、全文索引。 按照 物理实现方式 ,索引可以…

医疗器械中的国产光耦合器浅析

光耦合器,也称为光隔离器,在确保医疗器械的安全性和性能方面发挥着关键作用。通过在系统的不同部分之间提供电气隔离,它们可以防止信号干扰、保护敏感元件并保护患者免受电击。近年来,国产光耦合器制造商一直在加紧生产可靠的高性…

时也命也!转念的力量(深度好文)——早读(逆天打工人爬取热门微信文章解读)

时也命也 引言Python 代码第一篇 洞见 转念的力量(深度好文)第二篇 意想不到的收入结尾 早上上交所宕机 很多股票都横成直线 我的股却跳了一下水 我怕出什么监管事故 跟着卖出去了 然后查了一下 发现是上交所被买爆了 我想了一下 服务器问题 那么能否事后…

OpenEuler配置本地yum源

0x00 服务器版本 将本地镜像传输至服务器 操作步骤如下 # 创建一个目录用于挂载光盘映像 mkdir /media/cdrom/# 将光盘映像挂载到指定目录 mount /kvm/openeuler.iso /media/cdrom/#进入Yum仓库配置目录 cd /etc/yum.repos.d/# 备份原有的 openEuler.repo 文件 mv openEuler.…

解读: 火山引擎自研vSwitch技术

最近看到一篇文章介绍火山云的网络vSwitch技术,虽然是2022年的比较老的介绍,但是对于我们看到vSwitch技术的发展还是有些参考的。下面就截取了当时火山vSwitch关心的几个问题,做了一下梳理。 背景 在云计算发展过程中,虚拟网络的…

国内光耦合器制造商如何满足特殊行业的需求

在航空航天、国防、电信等行业,对定制解决方案的需求正在增长。通用光耦合器可能并不总是适合这些专业领域的特定要求,因为这些领域必须满足独特的环境条件、尺寸限制和性能基准。国内光耦合器制造商一直在加紧努力,提供可定制的解决方案&…

从 0 到 1:互联网产品经理核心技能全解析

在互联网的浩瀚海洋中,产品经理如同领航员,决定着产品从无到有的走向和命运。从 0 到 1 打造一款互联网产品,需要产品经理具备多方面的核心技能。今天,我们就来详细解读这些关键能力。 一、洞察市场趋势 时刻关注行业动态 互联网…

AOT源码解析4.1-对输入数据和mask进行处理(Associating Objects with Transformers for Video Object Segmentation)

论文阅读 papergithub论文阅读笔记AOT源码解析1-数据集处理AOT源码解析2-encoderdecoderAOT源码解析3-模型训练AOT源码解析4.1-model主体AOT源码解析4.2-model主体AOT源码解析4.3-model主体AOT源码解析4.4-model主体AOT源码解析4.5-model主体 输入数据 VOS的数据集处理操作可…

Python基础语句教学

Python是一种高级的编程语言,由Guido van Rossum于1991年创建。它以简单易读的语法和强大的功能而闻名,被广泛用于科学计算、Web开发、数据分析等领域。 Python的应用领域广泛,可以用于开发桌面应用程序、Web应用、游戏、数据分析、人工智能等…

【中台资料】数字中台建设资料合集(Word,PPT)

目录 1 编写目的 2 背景概述 3 中台概念 4 推动企业组织模式演进 5 建设方法 6 中台内容 7 数据安全体系 8 参考资料 软件全套资料部分文档清单: 工作安排任务书,可行性分析报告,立项申请审批表,产品需求规格说明书,需…

Redis 的 Java 客户端有哪些?官方推荐哪个?

Redis 官网展示的 Java 客户端如下图所示,其中官方推荐的是标星的3个:Jedis、Redisson 和 lettuce。 Redis 的 Java 客户端中,Jedis、Lettuce 和 Redisson 是最常用的三种。以下是它们的详细比较: Jedis: 线程安全&…

springboot在线教学平台

基于springbootvue实现的在线教学平台 (源码L文ppt)4-069 4.1系统结构设计 这些功能可以充分满足在线教学平台的需求。此系统功能较为全面如下图系统功能结构如图4-1所示。 图4-1功能结构图 4.2系统功能模块设计 在线教学平台的使用者主要有二类…

AI视频技术:引领影视剧拍摄的未来

大家好,我是Shelly,一个专注于输出AI工具和科技前沿内容的AI应用教练,体验过300款以上的AI应用工具。关注科技及大模型领域对社会的影响10年。关注我一起驾驭AI工具,拥抱AI时代的到来。 当科技遇见艺术,一场视听盛宴正…

华为GaussDB数据库之Yukon安装与使用

一、Yukon简介 Yukon(禹贡),基于openGauss、PostgreSQL、GaussDB数据库扩展地理空间数据的存储和管理能力,提供专业的GIS(Geographic Information System)功能,赋能传统关系型数据库。 Yukon 支…

破局汽车智能化浪潮:Tire 1供应商的网络优化与升级策略

在汽车行业经历电动化、智能化的深刻变革中,Tier 1供应商正面临着前所未有的挑战与机遇。Tier 1 供应商,即一级供应商,是汽车产业链中占据关键地位的合作伙伴。这类供应商不仅直接向整车制造商提供核心总成和模块,还深度参与整车的…

ISSCC 34.8 用于AI边缘设备的22nm,31.2TFLOPS/W,16Mb ReRAM存内浮点计算架构

本文将分享存内浮点计算前沿论文——ISSCC 2024《34.8 A 22nm 16Mb Floating-Point ReRAM Compute-in-Memory Macro with 31.2TFLOPS/W for AI Edge Devices》。下面将从文章基本信息、创新点解析、芯片测试与对比及未来展望四个部分展开介绍。 基本信息介绍 1、研究背景及面临…

QualiMap:一款强大的二代测序比对文件质控工具

在生物信息学中,数据质量的评估和可视化是很重要的一环。今天我们来聊聊一个常用的工具——Qualimap,它是一个用于评估高通量测序数据质量的开源软件,尤其是对RNA-seq和DNA测序数据的分析非常友好。无论你是本科生还是刚接触生物信息学的新人…

阿博图书馆管理:SpringBoot实战指南

第二章 开发技术介绍此次B/S结构、Java技术以及mysql数据库是该阿博图书馆管理系统的主要开发技术,然后对系统的整体设计、数据库设计、功能模块设计、系统页面设计以及系统程序设计进行了详细的研究与规划。 2.1 系统开发平台 在该阿博图书馆管理系统中&#xff0c…

大学学校用电安全远程监测预警系统

1.概述: 该系统是基于移动互联网、云计算技术,通过物联网传感终端,将办公建筑、学校、医院、工厂、体育场馆、宾馆、福利院等人员密集场所的电气安全数据,实时传输至安全用申管理服务器,为用户提供不间断的数据跟踪&a…