栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

【Python】matplotlib绘图的相关设置

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【Python】matplotlib绘图的相关设置

文章目录
    • 支持中文
    • 在Jupyter Notebook中显示清晰的图像
    • 画图风格设置
    • Marker和Linestyles属性设置
    • 坐标轴属性设置
    • 箭头标注
    • Artist 类及集成关系图
    • 官方推荐的参考资料

支持中文

在图像中使用中文,需要输入代码:

plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams['axes.unicode_minus'] = False

可以根据自己的需要来调整中文的字体,详见中文字体的英文名称对照表


在Jupyter Notebook中显示清晰的图像

在Juputer Notebook中显示清晰的图像,输入

%matplotlib inline
%config InlineBackend.figure_format = 'svg'

画图风格设置

使用 plt.style.use() 函数可以选择不同的画图风格,如

import matplotlib.pyplot as plt
plt.style.use('ggplot')


使用 plt.style.available 函数可查看所有内置的画图风格

import matplotlib.pyplot as plt
plt.style.available

或者,查看官方的示例参考文档:Style sheets reference


Marker和Linestyles属性设置
  • 数据点标记Marker属性:matplotlib.markers

  • 线型Linestyles属性:Linestyles, Line2D.set_linestyle


坐标轴属性设置
  • 所有支持的属性设置:matplotlib.axis
  • 坐标轴刻度设置的示例:Rotating custom tick labels

箭头标注

在坐标轴中使用箭头标注

(1)ConnectionPatch函数

  • ConnectionPatch函数:matplotlib.patches.ConnectionPatch
  • 示例:Connect Simple01 Using ConnectionPatch Function
  • ConnectionPatch支持的箭头属性设置:matplotlib.patches.ConnectionPatch
  • 箭头形状设置:matplotlib.patches.ArrowStyle

(2)annotate函数

  • annotate函数:matplotlib.axes.Axes.annotate
  • 示例:Broken Barh; Creating a timeline with lines, dates, and text
  • annotate函数中的text参数是不可缺少项,因此在不需要文字标注时不推荐使用annotate函数;

Artist 类及集成关系图

class matplotlib.artist.Artist

  • Abstract base class for objects that render into a FigureCanvas
    渲染为FigureCanvas的对象的抽象基类
  • Typically, all visible elements in a figure are subclasses of Artist.
    通常,figure中的所有可见元素都是Artist的子类。

Artist类的继承关系图:Inheritance Diagrams-matplotlib.artist


官方推荐的参考资料

官方推荐的参考资料:External resources

Ten Simple Rules for Better Figures


to be continued~

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/998520.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号