python_matplotlib DAY_22(2)patch作图,极坐标

学习内容
patch作图,极坐标
重点
1.matplotlib.patch作出图像

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mp#作图必须导入

a = np.array([0.5, 0.5])
ba = np.array([1, 1])
cba = np.array([1, 3])
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
circel=mp.Circle(a,0.5,color='r',alpha=0.3)#坐标,半径,颜色,透明度

ax.add_patch(circel)

rect=mp.Rectangle(ba,2,1,color='b',alpha=0.4)#坐标,长,宽
ax.add_patch(rect)

ploygon=mp.RegularPolygon(cba,5,1,color='y',alpha=0.35)
#坐标,多边形边数,中心到各个顶点的距离
ax.add_patch(ploygon)
plt.axis('equal')#坐标比例是1:1
plt.grid(linestyle=':')#显示网格
plt.show()

在这里插入图片描述
2.极坐标作图

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mp
plt.style.use('grayscale')
a = np.arange(1, 6)
b = np.pi / 2
c = [ b, 2 * b, 3 * b, 4 * b, 5 * b]
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
#projection='polar'就是转变成极坐标的核心语句
ax.plot(a, c, linestyle=':', color='r', linewidth=3)
plt.show()

在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mp

plt.style.use('grayscale')
a=np.empty(5)
a.fill(5)
b = np.pi / 2
c = [b, 2 * b, 3 * b, 4 * b, 5 * b]
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
ax.plot(c, a, color='r',marker="X",markersize=20)
ax.grid(True)
plt.show()

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值