06-03 Matplotlib
2021-10-28 15:05:41 1 举报
AI智能生成
登录查看完整内容
Matplotlib知识脉络,持续更新
作者其他创作
大纲/内容
Ten Simple Rules for Better Figures.pdf
图表展示规则 Ten Simple Rules for Better Figures
Matplotlib入门详细教程
Matlpotlib API概览官方文档
Data Visualisation with Matplotlib.pdf
格拉斯哥 Programming and System Development - Data Visualization
参考资料
conda install matplotlib
安装
import matplotlib.pyplot as plt
导入
%matplotlib inline
jupyter
入门
一开始的plt默认就有一个figure和axis,直接就可以画
更加复杂的面向对象方法需要在figure上创建axis坐标轴然后再画图
先使用plt.figure创建画布,然后使用add_**函数创建坐标轴
基本概念
matplotlib.axes
参考文档
axes
面向对象方式
实例
add_subplot()
add_axes()
面向对象figure作图法
colorbar
热度图(heatmap)
格式
散点图scatter
折线图plot
绘制图表
axes.set_title()
title
标题
legend
图例显示位置
grid
网格
text
添加文字
arrow
添加箭头
Matplotlib中annotate的简单用法
xy
参数
annotate
添加标记
axes.set_xlabel()
xlabel/ylabel
坐标轴标题
axis接受4个参数分别作为x和y轴的范围参数
axes.set_xlim()
axis/xlim/ylim
坐标轴范围
axes.xaxis.tick_top()
axes.xaxis.tick_bottom()
x坐标轴
axes.yaxis.tick_right()
axes.yaxis.tick_left()
y坐标轴
坐标轴位置
axes.set_frame_on(b=True)
是否显示坐标轴的长方形框框
坐标轴是否显示
axes.set_xticks()
xticks/yticks
坐标轴刻度范围
axes.set_xticklabels()
xticklabels/yticklabels
坐标轴刻度显示
坐标轴
配置图例
matplotlib.pyplot
pylpot
Matlab方式
subplot
subplots
位置更加自由,接收
解释
创建画板
'[marker][line][color]'
Markers
'-' solid line style'--' dashed line style'-.' dash-dot line style':' dotted line style
Line Styles
'b' blue'g' green'r' red'c' cyan'm' magenta'y' yellow'k' black'w' white
Colors
fmt
linewidth
**kwargs
参数解析
多组相同x坐标数组
多组不同表现数据
使用Dict传递数据
plot
折线图
c
marker
scatter
散点图
bar/barh
条形图
将输入的x数据按多少个bin显示
bins
hist
直方图
pie
饼图
countour
等高线图
imshow
图像
plt.legend()
使用画图函数定义时的label
默认
loc
传入画图函数的返回值,配合labels等确定顺序
handles
图例的说明
labels
plt.grid()
取值为‘both’, ‘x’,‘y’。就是以什么轴为刻度生成网格。例如我输入参数x就会在x轴方向上生成纵向的网格刻度。没有输入的方向则不会显示网格刻度。
axis
设置网格线的颜色。或者直接用c来代替color也可以
color
可以用ls来代替linestyle, 设置网格线的风格,是连续实线,虚线或者其它不同的线条。 | '-' | '--' | '-.' | ':' | 'None' | ' ' | '']
linestyle
网格线的宽度
表示标签添加的位置,默认是根据坐标轴的数据来度量的,是绝对值,也就是说图中点所在位置的对应的值,特别的,如果你要变换坐标系的话,要用到transform=ax.transAxes参数。
标签的符号,字符串格式,比如你想加个“我爱三行科创”,更多的是你标注跟数据有关的主体,你如实写便是。
s
加标签字体大小了,取整数
fontsize
垂直对齐方式 ,可选 ‘center’ ,‘top’ , ‘bottom’,‘baseline’
verticalalignment
水平对齐方式 ,可以填 ‘center’ , ‘right’ ,‘left’ 等
horizontalalignment
标签的旋转角度,以逆时针计算,取整
rotation
plt.xlabel()
plt.xlim()
plt.xticks()
plt.savefig(filename)
图片保存
Matplotlib
0 条评论
回复 删除
下一页