Python学习笔记(matplotlib篇)--形状

Python学习笔记--形状

  参靠视频:《Python数据可视化分析 matplotlib教程》链接:https://www.bilibili.com/video/av6989413/?p=6

所用的库及环境:

  IDE:Pycharm

  Python环境:python3.7

  Matplotlib:   Matplotlib 1.11

  Numpy:  Numpy1.15.

形状

  • 前言
    • 如何在一个图形中画一个填充好的形状,比如说画一个填充好的圆形,长方形,多边形
  • 代码及效果图
 1 import numpy as np
 2 import matplotlib.pyplot as plt
 3 import matplotlib.patches as mpathes
 4 
 5 fig,ax = plt.subplots()
 6 xy1 = np.array([0.2,0.2])
 7 xy2 = np.array([0.2,0.8])
 8 xy3 = np.array([0.8,0.2])
 9 xy4 = np.array([0.8,0.8])
10 #圆形
11 circle = mpathes.Circle(xy1,0.05)
12 ax.add_patch(circle)
13 #长方形
14 rect = mpathes.Rectangle(xy2,0.2,0.1,color='r')
15 ax.add_patch(rect)
16 #多边形
17 polygon = mpathes.RegularPolygon(xy3,5,0.1,color='g')
18 ax.add_patch(polygon)
19 #椭圆形
20 ellipse = mpathes.Ellipse(xy4,0.4,0.2,color='y')
21 ax.add_patch(ellipse)
22 
23 plt.axis('equal')
24 plt.grid()
25 plt.show()

 

  • 结语:

    感谢matplotlib提供的文档,感谢麦子学院提供的视频教学

posted @ 2018-09-19 09:32  9974  阅读(7263)  评论(0编辑  收藏  举报
快递查询