python【Matlibplot绘图库】绘制用于学术论文投稿的黑白图片
论文画图专用,数据numpy随机生成
文章目录
- 折线图
- 并列柱状图
- 箱线图
- 堆积折线图
- 三维曲面图
折线图
首先是最简单的折线图,每条线的color都是黑色,用linestyle加以区分,linestyle可以选择"-"、"–"、"-."、":“或”"。另外,坐标轴刻度、坐标轴名称、标签名称等等字体要调大一些,在figsize = (9, 6)的画布大小下我习惯把fontsize调成20,确保插入论文后字体大小看起来与正文中的小五一样大(当然不同的期刊可能也会有不同要求)。最后使用plt.savefig()保存图片,而不是
直接对IDE展示的图片右键保存(在本人电脑里这么保存的图片清晰度比较低),通过dpi参数调整需要保存图片的分辨率,我习惯设为300。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
sns.set_context("paper")np.random.seed(2020)
loss = pd.DataFrame({'A相线损': np.random.randn(96) + 15, 'B相线损': np.random.randn(96) + 10, 'C相线损': np.random.randn(96) + 5, '零线线损': np.random.randn(96)})fig, ax = plt.subplots(1, 1, figsize = (9, 6))
ax.plot(loss['A相线损'], color = 'k', label = 'A相线损', linestyle = '-')
ax.plot(loss['B相线损'], color = 'k', label = 'B相线损', linestyle = '--')
ax.plot(loss['C相线损'], color = 'k', label = 'C相线损', linestyle = '-.')
ax.plot(loss['零线线损'], color = 'k', label = '零线线损', linestyle = ':')
ax.set_xlabel('时间/5min', fontsize = 20)
ax.set_ylabel('线损/kWh', fontsize = 20)
ax.tick_params(labelsize = 20)
ax.legend(fontsize = 20)
plt.savefig('图1.jpg', dpi = 300)
plt.show()
并列柱状图
普通的柱状图没什么好说的,来看看并列柱状图。黑白图的关键在于sns.barplot()的参数palette,这里用到的是共有3种颜色的灰色调色板sns.color_palette(‘Greys’, 3)。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
sns.set_context("paper")np.random.seed(2020)
I = pd.DataFrame()
for i in range(1, 12):I_tmp = pd.DataFrame(columns = ['单元楼号', '相位', '电流/A'])I_tmp['相位'] = ['A相电流', 'B相电流', 'C相电流']I_tmp['电流'] = np.random.rand(3) * 10I_tmp['单元楼号'] = iI = pd.concat([I, I_tmp], axis = 0)fig, ax = plt.subplots(1, 1, figsize = (9, 6))
sns.barplot(x = '单元楼号', y = '电流', hue = '相位', data = I, palette = sns.color_palette('Greys', 3), ax = ax)
ax.set_xlabel('单元楼号', fontsize = 20)
ax.set_ylabel('电流/A', fontsize = 20)
ax.tick_params(labelsize = 20)
ax.legend(fontsize = 20)
plt.savefig('图2.jpg', dpi = 300)
plt.show()
箱线图
跟上面的并列柱状图差不多,为了做出黑白图同样用到的是palette = sns.color_palette('Greys', 2)。不同的是,并列柱状图中确定的x、y和hue只对应一个数字,而箱线图对应多个数字。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
sns.set_context("paper")np.random.seed(2020)
U_error = pd.DataFrame()
for index, phase in enumerate(['A相', 'B相', 'C相']):U_error_tmp = pd.DataFrame(columns = ['相位', '电压误差', '计算方法'])U_error_tmp['电压误差'] = np.random.rand(192) * 0.3 + 0.15 * indexU_error_tmp['相位'] = phaseU_error_tmp.loc[: 95, '计算方法'] = '本文方法'U_error_tmp.loc[96: , '计算方法'] = '对照方法'U_error = pd.concat([U_error, U_error_tmp], axis = 0)fig, ax = plt.subplots(1, 1, figsize = (9, 6))
sns.boxplot(x = '相位', y = '电压误差', hue = '计算方法', data = U_error, palette = sns.color_palette('Greys', 2), ax = ax)
sns.stripplot(x = '相位', y = '电压误差', hue = '计算方法', data = U_error, palette = sns.color_palette('Greys', 2), ax = ax, jitter = True, split = True)
ax.set_xlabel('相位', fontsize = 20)
ax.set_ylabel('电压误差/%', fontsize = 20)
ax.tick_params(labelsize = 20)
ax.legend(fontsize = 20)
plt.savefig('图3.jpg', dpi = 300)
plt.show()
堆积折线图
论文中也用到了堆积折线图,因为每两条折线之间的区域都需要通过一个语句填充颜色,没法像上两张图一样用palette = sns.color_palette(‘Greys’, n)来直接填充,但我一次意外发现,用sns.color_palette()[]就能直接指定这个调色板中的每个颜色了。下面的图片需要区分四种颜色,考虑到调色板里的第一个颜色太浅,最后一个颜色太深,我选择了6种颜色的调色板sns.color_palette(‘Greys’, 6),取其中1~4进行单独的颜色填充。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
sns.set_context("paper")np.random.seed(2020)
power = pd.DataFrame(np.random.randn(8, 24))
power = (power - power.min().min()) * 100
power.index = [str(i) + '00MW机组' for i in range(8, 0, -1)]
p_cumsum = np.cumsum(power)fig, ax = plt.subplots(1, 1, figsize = (9, 6))
ax.fill_between(p_cumsum.columns, p_cumsum.iloc[6], p_cumsum.iloc[7], facecolor = sns.color_palette('Greys', 6)[4], hatch = '/', label = p_cumsum.index[7])
ax.fill_between(p_cumsum.columns, p_cumsum.iloc[5], p_cumsum.iloc[6], facecolor = sns.color_palette('Greys', 6)[3], hatch = '/', label = p_cumsum.index[6])
ax.fill_between(p_cumsum.columns, p_cumsum.iloc[4], p_cumsum.iloc[5], facecolor = sns.color_palette('Greys', 6)[2], hatch = '/', label = p_cumsum.index[5])
ax.fill_between(p_cumsum.columns, p_cumsum.iloc[3], p_cumsum.iloc[4], facecolor = sns.color_palette('Greys', 6)[1], hatch = '/', label = p_cumsum.index[4])
ax.fill_between(p_cumsum.columns, p_cumsum.iloc[2], p_cumsum.iloc[3], facecolor = sns.color_palette('Greys', 6)[4], label = p_cumsum.index[3])
ax.fill_between(p_cumsum.columns, p_cumsum.iloc[1], p_cumsum.iloc[2], facecolor = sns.color_palette('Greys', 6)[3], label = p_cumsum.index[2])
ax.fill_between(p_cumsum.columns, p_cumsum.iloc[0], p_cumsum.iloc[1], facecolor = sns.color_palette('Greys', 6)[2], label = p_cumsum.index[1])
ax.fill_between(p_cumsum.columns, 0, p_cumsum.iloc[0], facecolor = sns.color_palette('Greys', 6)[1], label = p_cumsum.index[0])
ax.set_xlabel('时间', fontsize = 18)
ax.set_ylabel('各类型机组出力/MW', fontsize = 18)
plt.xticks([i for i in range(0, 24, 3)], [str(i) + ':00' for i in range(0, 24, 3)])
ax.tick_params(labelsize = 18)
ax.legend(fontsize = 18)
plt.savefig('图4.jpg', dpi = 300)
plt.show()
除此之外,使用调色板sns.color_palette()的时候,还可以用函数sns.palplot()来展示调色板中的各种颜色。
三维曲面图
在Python中使用颜色映射colormap,也是能得到黑白三维曲面图的。黑白图的关键在ax.plot_surface()的参数cmap,使用颜色映射plt.cm.gray就能得到黑白的三维曲面图了。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from mpl_toolkits.mplot3d import Axes3D
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
sns.set_context("paper")data = pd.DataFrame(index = np.arange(0, 1.05, 0.1), columns = np.arange(0, 1.05, 0.1))
for i in range(data.shape[0]):for j in range(data.shape[1]):data.iloc[i, j] = np.sin(data.index[i] + data.index[j])
X, Y = np.meshgrid(data.index, data.columns)fig = plt.figure(figsize = (9, 6))
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, data, rstride = 1, cstride = 1, cmap = plt.cm.gray)
plt.xticks([0, 0.2, 0.4, 0.6, 0.8, 1], ['0%', '10%', '20%', '30%', '40%', '50%'])
plt.yticks([0, 0.2, 0.4, 0.6, 0.8, 1], ['0%', '10%', '20%', '30%', '40%', '50%'])
ax.tick_params(labelsize = 16, pad = 0, axis = 'x')
ax.tick_params(labelsize = 16, pad = 0, axis = 'y')
ax.tick_params(labelsize = 16, pad = 2, axis = 'z')
ax.set_xlabel('光伏占比', fontsize = 16, rotation = -11, labelpad = 4)
ax.set_ylabel('风电占比', fontsize = 16, rotation = 40)
ax.set_zlabel('抽蓄抽水功率/MW', fontsize = 16, labelpad = 2)
plt.savefig('图6.jpg', dpi = 300)
plt.show()
python【Matlibplot绘图库】绘制用于学术论文投稿的黑白图片相关推荐
- python 3d绘图库_python – 用于科学3d绘图的Mayavi的替代品
在没有令人满意的第一个答案和无法解释的downvote之后编辑: 我需要绘制一个在3D网格中构造的标量字段,如下所示: import numpy as np from mayavi import ml ...
- 用python画皮卡丘画法-python turtle绘图库绘制【皮卡丘】源码
直接可运行,然后仔细看看代码,自己敲一敲吧. # !/usr/bin/env python3 # -*- coding: utf-8 -*- # @Author: ai8py # @Date: 201 ...
- python pyqtgraph绘图库-绘制图形
绘制波形 设置plot的pen属性的几种方法,通过画笔可以设置绘制图像的颜色.线宽等参数: pen=(255,0,0) pen=pg.mkPen(color='b', width=5) pen=pg. ...
- python【Matlibplot绘图库】利用matlibplot绘制雷达图
文章目录 1.基本构造 2.比较功能 1.基本构造 之前在一些数据分析案例中看到用 Go 语言绘制的雷达图,非常的漂亮,就想着用matlibplot.pyplot也照着画一个,遗憾的是matlibpl ...
- python【Matlibplot绘图库】-主要概念
文章目录 1.概述 2.各函数含义 3.numpy处理数据 1.概述 Matplotlib的GitHub链接: https://github.com/matplotlib/matplotlibMatp ...
- python安装绘图库matplotlib_Python基础教程:Python 2D绘图库 Matplotlib 简介和安装
原标题:Python基础教程:Python 2D绘图库 Matplotlib 简介和安装 来自:Linux迷https://www.linuxmi.com/python-2d-matplotlib.h ...
- python 三维绘图库_Python第三方库matplotlib(2D绘图库)入门与进阶
Matplotlib 一 简介: Matplotlib是一个Python 2D绘图库,它可以在各种平台上以各种硬拷贝格式和交互式环境生成出具有出版品质的图形. Matplotlib可用于Python脚 ...
- 在学术论文投稿时你遇到过最奇葩的审稿意见是什么?
全世界只有3.14 % 的人关注了 数据与算法之美 论文投稿时,总会收到点奇葩审稿意见.就连大名鼎鼎的爱因斯坦也被美国<物理评论>期刊的审稿人怼过,审稿人认为文章的内容和结论存在严重问题, ...
- CVPR 2021 审稿意见出了,你也许需要这份学术论文投稿与返修指南
本文转载自知乎,已获作者授权转载. 链接:https://zhuanlan.zhihu.com/p/344008879 讲座内容:本文内容主要是基于笔者在学院内部一次分享讲座整理而来.以笔者近期的几篇 ...
最新文章
- The Six Best Practices(1~3)
- 为什么要选择Apache Pulsar(一)
- vc:如何从Internet上有效而稳定地下载文件
- 【转】typedef函数指针的用法(C++)
- 不用计算实现 图片懒加载
- C#基础之如何判断两个文件内容是否相同
- java xy,java – 某个z深度的xy位置
- C++ vector
- pytorch学习笔记(二十九):简洁实现循环神经网络
- .NET dnSpy 程序集编辑器,反编译器和调试器
- 对梯度提升树(GBDT)的通俗理解
- 计算机类学术期刊SCI/EI期刊核心期刊有哪些?
- OpenFOAM 学习笔记
- 这个屡获大奖的Firefox浏览器又推出新版本啦,完全免费
- iOS之苹果和百度地图的使用
- PTA 7-274 魔镜
- 一个渗透自学者的自述
- torch.chunk用法
- mac vim常用简单命令
- Python中 and 和 or 运算短路逻辑
热门文章
- Could not decode a text frame as UTF-8 的解决
- Ubuntu 安装 scikit-image
- EigenUbuntu下的配置
- 利淘优选——青龙羊毛
- Linux系统卸载Apache(阿帕奇)环境教程
- 66 Airflow安装与部署
- 性能案例-Linux下解决time_wait连接过多(Linux内核优化)
- 渗透知识-XSS跨站脚本攻击
- html+li标签+高度,有时在使用Jquery插入LI元素时,JavaScript不会调整UL元素的高度
- android开发实例之viewpager无限循环+自动滚动,Android ViewPager实现无限循环的实例...