python matplotlib数据可视化(六)(折线绘圆,椭圆绘圆,楔形绘饼图,楔形绘圆环饼图)

用折线图绘制圆

# 导入包
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
import numpy as np

# 绘图
fig,ax = plt.subplots(2,2)
x=np.linspace(0,2*np.pi,500)
y1=2*np.cos(x)
y2=2*np.sin(x)

# subplot(221)
ax[0,0].plot(y1,y2,color='cornflowerblue',lw=2)
# 不懂这里为什么plot(y1,y2就能画出来圆了)
ax[0,0].set_xlim(-3,3)
ax[0,0].set_ylim(-3,3)

# subplot(222)
rectangle=ax[0,1].patch
rectangle.set_facecolor('gold')
ax[0,1].plot(y1,y2,color='cornflowerblue',lw=2)
ax[0,1].set_xlim(-3,3)
ax[0,1].set_ylim(-3,3)
ax[0,1].set_aspect('equal','box')
# x,y轴的刻度线的变化量不同,采用ax[0,1].set_aspect('equal','box')使其相同

# subplot(223)
rectangle=ax[1,0].patch
rectangle.set_facecolor('palegreen')
ax[1,0].plot(y1,y2,color='cornflowerblue',lw=2)
ax[1,0].set_aspect('equal','box')

# subplot(224) 见详解1有代码变换
rectangle=ax[1,0].patch
rectangle.set_facecolor('lightskyblue')
ax[1,1].plot(y1,y2,color='cornflowerblue',lw=2)
ax[1,1].axis([-3,3,-3,3])
ax[1,1].set_yticks(np.arange(-3,4,1))
ax[1,1].axis('equal')
# 相比(222)将刻度线的变化量进行调整,使之保持相同的增量,不进行x,y轴的坐标轴显示范围的操作

plt.subplots_adjust(left=0.1) # 详解2

plt.show()

在这里插入图片描述

详解1:

# subplot(224)
rectangle=ax[1,0].patch
rectangle.set_facecolor('lightskyblue')
ax[1,1].plot(y1,y2,color='cornflowerblue',lw=2)
ax[1,1].axis([-3,3,-3,3])
ax[1,1].set_yticks(np.arange(-3,4,1))
ax[1,1].axis(&#
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值