Python画图常用命令大全(详解)
作者:罗平生 时间:2023-04-17 15:20:16
matplotlib官网
matplotlib库默认英文字体
添加黑体(‘SimHei')为绘图字体
代码:
plt.rcParams['font.sans-serif']=['SimHei']
1. 简单例程柱状图
基本方法:matplotlib.pyplot.bar()
基本参数:bar(x,y)
其他参数:颜色color 宽度width 透明度alpha
其他方法:图例legend() 横轴定义xlable() 纵轴定义ylable() 图标题title() 刻度方法xlim(), ylim()
import matplotlib.pyplot as plt #绘图
import pandas as pd #读取exal文件
plt.rcParams['font.sans-serif']=['SimHei'] #添加黑体作为绘图字体
name = ['tom', 'rose', 'lucy']#变量name装了一个列表
weight = [60, 70, 80]#具有位置属性和数值属性
plt.bar(name, weight, label='体重', color='green', alpha=0.5, width=0.5) #从库里面调用方法+图例+颜色+透明度+宽度
plt.xlabel('姓名')
plt.ylabel('体重 单位kg')
plt.title('三个人的体重xx')
plt.legend()
plt.savefig('柱状图.png', dip=500)
plt.show() #显示方法
2. 读取exal方法
2.1 数据处理常用库:pandas
用pandas读取excel文件的常用方法:read_excel() 参数是文件名
import matplotlib.pyplot as plt #绘图
import pandas as pd #读取exal文件
Data = pd.read_excel('E:\PythonData/LandingData.xlsx')
print(Data)
注意文件路径开头不要是数字,不然报错
E:\PythonData/LandingData.xlsx
2.2 提取列表数组
3. 论文图片的类型和格式
位图(放大后有马赛克):.jpg .tif .psd .bmp .png
矢量图(放大也很清晰):.wmf .emf .epd .cdx
事物摄影使用位图,
.png格式是非可拓展文件类型;.pdf是可拓展文件格式,pdf是矢量图。
4. 柱状图扩展
4.1 堆叠柱状图
4.2 分解柱状图
5. Python绘制折线图坐标无法显示负号
添加如下代码即可
import matplotlib
matplotlib.rcParams['axes.unicode_minus']=False
plt.rcParams['axes.unicode_minus']=False
6. Python坐标轴显示汉字
plt.rcParams['font.sans-serif']=['SimHei'] #添加黑体作为绘图字体
来源:https://blog.csdn.net/Roger_717/article/details/120530151
标签:Python,画图,命令
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python3 SSH远程连接服务器的方法示例
2021-02-15 17:50:05
![](https://img.aspxhome.com/file/2023/8/124918_0s.png)
鼠标驱动图片变化
2009-07-26 10:03:00
检测python爬虫时是否代理ip伪装成功的方法
2021-07-31 20:23:44
Python实现孤立随机森林算法的示例代码
2021-11-25 14:38:24
![](https://img.aspxhome.com/file/2023/6/131346_0s.jpg)
Python pymsql模块的使用
2023-01-08 15:23:00
![](https://img.aspxhome.com/file/2023/0/114770_0s.gif)
python2爬取百度贴吧指定关键字和图片代码实例
2022-10-12 09:03:44
动态给表添加删除字段并同时修改它的插入更新存储过程
2011-12-01 10:18:28
DW MX新功能试用:嵌套模板
2008-02-03 11:35:00
![](https://img.aspxhome.com/file/UploadPic/20072/200723113533349s.jpg)
教你用python实现12306余票查询
2021-03-16 01:39:19
![](https://img.aspxhome.com/file/2023/7/75167_0s.png)
python使用参数对嵌套字典进行取值的方法
2022-04-12 10:13:27
MSSQL中递归SQL查询语句实例说明-
2024-01-28 19:54:01
![](https://img.aspxhome.com/file/2023/4/88264_0s.gif)
vue实现登录拦截
2024-04-30 10:25:20
![](https://img.aspxhome.com/file/2023/6/130216_0s.jpg)
python实时监控logstash日志代码
2021-03-08 07:46:49
python下对hsv颜色空间进行量化操作
2022-11-22 01:56:12
![](https://img.aspxhome.com/file/2023/6/93966_0s.jpg)
如何使用SublimeText3配置 PHP IDE环境
2024-04-30 09:58:51
![](https://img.aspxhome.com/file/2023/9/131619_0s.png)
CentOS 7安装Mysql并设置开机自启动的方法
2024-01-27 05:32:47
mysql 导入导出数据库以及函数、存储过程的介绍
2024-01-20 15:26:51
使用vue打包时gzip压缩的两种方案
2024-05-21 10:29:45
![](https://img.aspxhome.com/file/2023/1/123931_0s.jpg)
分析语音数据增强及python实现
2021-02-02 07:25:43
![](https://img.aspxhome.com/file/2023/8/118398_0s.png)
基于Python把网站域名解析成ip地址
2021-08-23 05:31:06
![](https://img.aspxhome.com/file/2023/8/87928_0s.png)