用matplotlib画复杂的二维数学函数坐标图像

一、笛卡尔心形图

import numpy as np
import matplotlib.pyplot as plt

a = 1
t = np.linspace(0, 2*np.pi)
X = a*(2*np.cos(t) - np.cos(2*t))/2
Y = a*(2*np.sin(t) - np.sin(2*t))

plt.plot(Y, X, c = 'r')
plt.show()

结果:
在这里插入图片描述

二、三叶草图形

在这里插入图片描述

from numpy import *
import matplotlib.pyplot as plt

n = int(2*pi/0.01)
t = linspace(0, 2*pi, n)
wh, hh = 0.5, 0.5
x = (2 / 3) * wh * sin(3*t) * cos(t)
y = (2 / 3) * hh * sin(3*t) * sin(t)

#创建画布并引入axisartist工具。
import mpl_toolkits.axisartist as axisartist
#创建画布
fig = plt.figure(figsize=(6, 6))
#使用axisartist.Subplot方法创建一个绘图区对象ax
ax = axisartist.Subplot(fig, 111)
#将绘图区对象添加到画布中
fig.add_axes(ax)

ax.axis[:].set_visible(False)#通过set_visible方法设置绘图区所有坐标轴隐藏
ax.axis["x"] = ax.new_floating_axis(0,0)#ax.new_floating_axis代表添加新的坐标轴
ax.axis["x"].set_axisline_style("->", size = 1.0)#给x坐标轴加上箭头

#添加y坐标轴,且加上箭头
ax.axis["y"] = ax.new_floating_axis(1,0)
ax.axis["y"].set_axisline_style("->", size = 1.0)
#设置x、y轴上刻度显示方向
ax.axis["x"].set_axis_direction("top")
ax.axis["y"].set_axis_direction("right")
plt.plot(x, y, c = 'b')
plt.xlim(-0.5, 0.5)
plt.ylim(-0.5, 0.5)
plt.show()

结果:
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值