Python Class
matplotlib.pyplot
创建图表
| 函数 | 描述 | 参数 |
|---|---|---|
plt.plot() |
创建折线图 | x (可选), y, label, color, linestyle, marker |
plt.bar() |
创建柱状图 | x, height, width, label, color |
plt.barh() |
创建水平柱状图 | y, width, height, label, color |
plt.scatter() |
创建散点图 | x, y, s (大小), c (颜色), marker |
plt.hist() |
创建直方图 | x, bins, color, label |
plt.pie() |
创建饼图 | sizes, labels, autopct, colors, startangle |
plt.boxplot() |
创建箱线图 | x, labels, patch_artist |
设置图表标题和标签
| 函数 | 描述 | 参数 |
|---|---|---|
plt.title() |
设置图表标题 | label, fontsize, color, loc, fontweight, pad |
plt.xlabel() |
设置 X 轴标签 | label, fontsize, color, labelpad |
plt.ylabel() |
设置 Y 轴标签 | label, fontsize, color, labelpad |
plt.xticks() |
设置 X 轴刻度 | ticks, labels, rotation, fontsize |
plt.yticks() |
设置 Y 轴刻度 | ticks, labels, rotation, fontsize |
plt.legend() |
添加图例 | loc, fontsize, shadow, title |
plt.grid() |
添加网格 | which, axis, linestyle, color |
plt.subplots() |
创建多个子图 | nrows, ncols, figsize, sharex, sharey |
plt.subplot() |
创建单个子图 | nrows, ncols, index |
plt.show() |
显示图表 | 无 |
plt.savefig() |
保存图表 | fname, dpi, format, bbox_inches |
plt.xlim() |
设置 X 轴范围 | left, right |
plt.ylim() |
设置 Y 轴范围 | bottom, top |
自定义样式
| 函数 | 描述 | 参数 |
|---|---|---|
plt.rcParams |
设置全局样式 | key, value |
plt.style.use() |
使用预定义的样式表 | style |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Frite的个人博客!