1. 17、彻底弄清matplotlib Figure中各个元素的含义_笔记
    2. print(mpl.__version__)
    3. # python最常用的绘图库,提供了一整套十分适合交互式绘图的命令API,比较方便的就可以将其嵌入到
    4. # GUI应用程序中
    5. # 官网:http://matplotlib.org/
    6. # figure和subplot
    7. # Figure:面板图,matplotlib中的所有图像都是位于figure对象中,一个图像只能有一个figure对象 类似于一块黑板 画板
    8. # Subplot:子图,figure对象下创建一个或多个subplot对象(即axes)用于绘制图表
    9. # 设置figsize=8*6 分辨率为80
    10. # defaults to rc figure.figsize
    11. # 获取figure对象,方便在其上面创建子图即axes对象
    12. # 获取所有的自带样式 # 设置图形的显示风格
    13. # 颜色 标记 线型 color marker linestyle
    14. # 设定x轴 y轴的范围 刻度 标签
    15. # 保存图片文件 必须放到show方法之前
    16. # plt.savefig('ai111.png', dpi=200)
    17. # -*- coding: utf-8 -*-
    18. __author__ = 'dongfangyao'
    19. __date__ = '2018/1/6 下午12:15'
    20. __product__ = 'PyCharm'
    21. __filename__ = 'matplotlib3'
    22. import matplotlib as mpl
    23. import matplotlib.pyplot as plt
    24. import numpy as np
    25. mpl.rcParams['font.family'] = 'sans-serif'
    26. mpl.rcParams['font.sans-serif'] = ['SimHei']
    27. mpl.rcParams['axes.unicode_minus'] = False
    28. print(mpl.__version__)
    29. # defaults to rc figure.figsize
    30. print(mpl.rcParams['figure.figsize'])
    31. # 取到figure对象 方便我们创建子图 axes对象
    32. figure = plt.figure(figsize=(6, 8), dpi=80)
    33. axes1 = figure.add_subplot(2, 2, 1)
    34. # axes2 = figure.add_subplot(2, 2, 2)
    35. # axes3 = figure.add_subplot(2, 2, 3)
    36. # axes4 = figure.add_subplot(2, 2, 4)
    37. # 设置图标的显示风格
    38. print(plt.style.available)
    39. # plt.style.use('ggplot')
    40. x = np.arange(-5, 5)
    41. # x = np.linspace(-np.pi, np.pi, 256, endpoint=True)
    42. y = np.sin(x)
    43. # print(x, y)
    44. # 设置x轴 y轴的范围
    45. # plt.axis([-5, 5, -5, 5])
    46. plt.xlim(-5, 5)
    47. plt.ylim(-5, 5)
    48. plt.xlabel(u'我是X轴')
    49. plt.ylabel(u'我是Y轴')
    50. plt.xticks(np.arange(-3, 3))
    51. plt.yticks(np.arange(-1, 3))
    52. plt.title(u'我是标题')
    53. plt.text(-3, -3, '$y=sin(x)
    54. [/align][/size][/font][/align]
    55. , fontsize=20, bbox={'facecolor': 'yellow', 'alpha': 0.2})
    56. # plt.grid = True
    57. # 颜色 线型 标记
    58. # help(plt.plot)
    59. plt.plot(x, y, color='r', linestyle='--', marker='o')
    60. # 保存图片
    61. plt.savefig('ai111.png', dpi=200)
    62. # plt.legend()
    63. plt.show()
    64. 复制代码
    65. # 去除右边和上边的边框
    66. axes1.spines['right'].set_color('None')
    67. axes1.spines['top'].set_color('None')