文章目录

  • 前言
  • 图(一)
  • 图(二)
  • 图(三)
  • 图(四)

前言

论文实验部分通常需要画各种图,可视化使效果更直观,本文总结和整理几种论文中常见的图的python实现方法。

图(一)


实现代码

import numpy as np
import matplotlib.pyplot as pltnp.random.seed(19680801)n_bins = 10
x = np.random.randn(1000, 3)fig, axes = plt.subplots(nrows=2, ncols=2)
ax0, ax1, ax2, ax3 = axes.flatten()colors = ['red', 'tan', 'lime']
ax0.hist(x, n_bins, density=True, histtype='bar', color=colors, label=colors)
ax0.legend(prop={'size': 10})
ax0.set_title('bars with legend')ax1.hist(x, n_bins, density=True, histtype='bar', stacked=True)
ax1.set_title('stacked bar')ax2.hist(x, n_bins, histtype='step', stacked=True, fill=False)
ax2.set_title('stack step (unfilled)')# Make a multiple-histogram of data-sets with different length.
x_multi = [np.random.randn(n) for n in [10000, 5000, 2000]]
ax3.hist(x_multi, n_bins, histtype='bar')
ax3.set_title('different sample sizes')fig.tight_layout()
plt.show()

图(二)


实现代码

import numpy as np
import matplotlib.pyplot as plt
# # // 设置中文字体
# font_set = FontProperties(fname=r"***path***/mpl-data/fonts/simfang.ttf")
# # // 设置生成图片的分辨率
# matplotlib.rcParams['figure.figsize']
# matplotlib.rcParams['savefig.dpi']
# plt.rcParams['font.sas-serig']=['simfang']
# plt.rcParams['axes.unicode_minus']=Falsen_groups = 5
class1 = (10, 15,20, 25, 30)
class2 = (30, 35, 40, 45, 50)
class3 = (50, 55, 60,65, 70)fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.2
opacity = 0.5
error_config = {'ecolor': '0.3'}
rects1 = ax.bar(index, class1, bar_width,alpha=opacity, color='indianred',error_kw=error_config,label='class 1')
rects2 = ax.bar(index + bar_width, class2, bar_width,alpha=opacity, color='#106D9C',error_kw=error_config,label='class 2')
rects3 = ax.bar(index + bar_width + bar_width, class3, bar_width,alpha=opacity, color='#00A2DE',error_kw=error_config,label='class 3')ax.set_xticks(index + 3 * bar_width / 3)
ax.set_xticklabels(('1', '2', '3', '4', '5'))
ax.legend()
plt.xlabel(u"X")
plt.ylabel(u'Count')
fig.tight_layout()
# plt.savefig('result.png', dpi=200)
plt.grid(ls='-.')  # 绘制背景线
plt.show()

图(三)


实现代码

from matplotlib import pyplot as plta = ["item1","item2", "item3"]
b_1 = [0.72, 0.5, 0.85]
b_2 = [0.74, 0.64, 0.71]
b_3 = [0.84, 0.55, 0.56]
b_4 = [0.85, 0.7, 0.86]  height = 0.2
a1 = list(range(len(a)))
a2 = [i-height for i in a1]#坐标轴偏移
a3 = [i-height*2 for i in a1]
a4 = [i-height*3 for i in a1]plt.barh(range(len(a)),b_1,height= height,label = "class1",color = "c", alpha=0.7)
plt.barh(a2,b_2, height= height, label = "class2", color = "b", alpha=0.7)
plt.barh(a3,b_3,height= height,label = "class3",color = "y", alpha=0.7)
plt.barh(a4,b_4,height= height,label = "class4",color = "r", alpha=0.7) #绘制网格
plt.grid(alpha = 0.4,ls='-.')
#y轴坐标刻度标识
plt.yticks(a2,a)
#添加图例
plt.legend()
#添加横纵坐标,标题
plt.xlabel("value")
# plt.ylabel("name")
# plt.title("title")
plt.xlim(xmax = 1.0)
plt.tight_layout()
plt.show()

图(四)


实现代码

import matplotlib.pyplot as plt
import numpy as npx = [10, 20, 30, 40, 50]
y1 = [4, 4, 5, 2, 1]
y2 = [3, 2, 1, 4, 2]
y3 = [2, 1, 4, 5, 3]
y4 = [1, 3, 2, 3, 4]
#绘制折线图,添加数据点,设置点的大小
# 此处也可以不设置线条颜色,matplotlib会自动为线条添加不同的颜色
plt.plot(x, y1, alpha=1, color="c", marker='*', markersize=7)
plt.plot(x, y2, alpha=1, color='b', marker='x',markersize=7)
plt.plot(x, y3, alpha=1, color='y', marker='o',markersize=7)
plt.plot(x, y4, alpha=1, color='r', marker='^',markersize=7)
# plt.yticks(np.arange(0.5, 3.25, step=0.25))
# plt.ylim(ymin=-0.005)
# plt.xticks(np.arange(8, 70, step=8))
plt.title('title')  # 折线图标题
plt.xlabel('X')  # x轴标题
plt.ylabel('Y')  # y轴标题
plt.grid(ls='-.')  # 绘制背景线
plt.legend(['item1', 'item2', 'item3', 'item4'])
plt.tight_layout()
plt.show()

python matpltlib实践——画直方图、折线图相关推荐

  1. [python] Jupyter Notebook 画股票折线图

    1. Jupyter Notebook 是一个web python应用程序,它可以支持实时代码和画图 安装命令如下 pip install jupyter -i https://pypi.douban ...

  2. python使用matplotlib可视化:折线图、条形图、柱状图、直方图、饼图、雷达图(极坐标图)

    python使用matplotlib可视化:折线图.条形图.柱状图.直方图.饼图.雷达图(极坐标图) 目录

  3. python plt 画动态折线图

    python plt 画动态折线图 # coding=utf-8import matplotlib.pyplot as plt import numpy as npdef main():plt_lis ...

  4. matplotlib画的折线图

    文章最前: 我是Octopus,这个名字来源于我的中文名--章鱼:我热爱编程.热爱算法.热爱开源.所有源码在我的个人github :这博客是记录我学习的点点滴滴,如果您对 Python.Java.AI ...

  5. [转载] Python数据可视化库-Matplotlib——折线图绘制

    参考链接: Python Matplotlib数据可视化 plot折线图 # coding:utf-8 import pandas as pd import numpy as np from matp ...

  6. python 画图--简单开始及折线图

    python 画图--简单开始及折线图 本博客转载自:http://blog.csdn.net/jenyzhang/article/details/52046372 相关参考资料:        ma ...

  7. python_pyecharts画三维折线图

    1.摘要 本文主要讲解:使用python中的pyecharts画三维折线图 主要思路: 将数据处理成[[x-],[y-],[z-]]的形式 使用Line3D函数渲染 2.数据介绍 数据为简单的三维数据 ...

  8. 【python】如何画简单的图

    [python学习]画简单的图 一般是引用turtle这个函数库来画图,这个画图就好像一个乌龟在白纸上爬,其爬行轨迹就是所画的图形. 一些基本的语句: import turtle 用来引用turtle ...

  9. python 可视化 ploty 画3dmesh网格图

    python 可视化 plotly 画3dmesh网格图 最近在工作中遇到python 打印可视化3D图.需求是根据以下CSV文件黄色高亮的三列打印3D立体网格图,尝试过用matplotlib打印出来 ...

  10. python matplotlib绘制多条折线图

    python matplotlib绘制多条折线图 代码 import matplotlib.pyplot as pltx = [6, 24, 48, 72] y1 = [87, 174, 225, 2 ...

最新文章

  1. 某口腔app发现了不友善词汇(f*ckMobile)
  2. python下载mp4
  3. 关于position的四个标签
  4. Java-Type简单分类
  5. ubuntu下打开matlab_ubuntu下matlab安装,添加中文支持与启动
  6. Eclipse或MyEclipse—在Eclipse或MyEclipse中如何将jar包和相应的源代码关联起来
  7. Webpower中国区发布《2015年中国金融保险行业邮件营销市场报告》
  8. 单例模式中的饿汉和懒汉模式
  9. 蜂窝网络版苹果iPad mini 6不支持毫米波5G
  10. java对象的哈希值_对象的哈希值
  11. 工业机器人远程监控运维物联网解决方案
  12. Ttest + 秩和检验
  13. 修改select下拉箭头 使用背景图片
  14. 揭秘华为投资版图:规模小、数量少,刀刀致命
  15. win11系统下,不断弹出关机窗口
  16. 如何开好项目验收会?
  17. GICv3-4零散的寄存器解读(1)
  18. 删除桌面“恶意”图标
  19. 水务局保密计算机台账管理办法,关于建立取水台账登记管理制度的通知
  20. 【财富空间】大润发创始人挥泪离场:我战胜了所有对手,却输给了时代!

热门文章

  1. spurious wakeup虚假唤醒
  2. 2021年微信小程序应用开发大赛华南赛区获奖作品---《课室帮》上
  3. python爬虫实现大麦抢票_爬虫 大麦网
  4. python如何实现手眼定标_kafka基础和python如何操作kafka
  5. 关于舵轮AGV 的数学模型
  6. 微信小程序:音乐播放器(附源码)
  7. html怎么把图片左移_css怎么让图片向左移动?
  8. 不同系统下的shell的不同_案例分析 | 不同安装角度下平板集热器阳台壁挂式太阳能热水系统性能分析...
  9. STREAM内存带宽测试工具介绍及其内部实现
  10. 随心测试_Python Se_003操作浏览器对象