python绘制笛卡尔心形曲线_如何在python的极图中显示笛卡尔系统?

在这里,我试图将极坐标图添加到笛卡尔网格的顶部,但是我得到的是2个单独的图形(一个极坐标另一个笛卡尔坐标),我希望将此极坐标图嵌入到笛卡尔坐标图中.我还使用了一些以前可用的代码,因为我是matplotlib的新手.

from pylab import *

import matplotlib.pyplot as plt

x = [0,10,-3,-10]

y = [0,10,1,-10]

color=['w','w','w','w']

fig = plt.figure()

ax1 = fig.add_subplot(111)

scatter(x,y, s=100 ,marker='.', c=color,edgecolor='w')

circle1=plt.Circle((0,0),5,color='r',fill=False)

circle_min=plt.Circle((0,0),4.5,color='g',fill=False)

circle_max=plt.Circle((0,0),5.445,color='b',fill=False)

fig = plt.gcf()

fig.gca().add_artist(circle1)

fig.gca().add_artist(circle_min)

fig.gca().add_artist(circle_max)

left,right = ax1.get_xlim()

low,high = ax1.get_ylim()

arrow( left, 0, right -left, 0, length_includes_head = True, head_width = 0.15 )

arrow( 0, low, 0, high-low, length_includes_head = True, head_width = 0.15 )

grid()

fig = plt.figure()

ax2 = fig.add_subplot(111)

scatter(x,y, s=100 ,marker='.', c=color,edgecolor='w')

circle2=plt.Circle((0,0),5,color='r',fill=False)

circle_min=plt.Circle((0,0),4.5,color='g',fill=False)

circle_max=plt.Circle((0,0),5.445,color='b',fill=False)

fig = plt.gcf()

fig.gca().add_artist(circle2)

fig.gca().add_artist(circle_min)

fig.gca().add_artist(circle_max)

left,right = ax2.get_xlim()

low,high = ax2.get_ylim()

arrow( left, 0, right -left, 0, length_includes_head = True, head_width = 0.15 )

arrow( 0, low, 0, high-low, length_includes_head = True, head_width = 0.15 )

import numpy as np

import matplotlib.pyplot as plt

theta = np.linspace(-np.pi, np.pi, 100)

r1 = 1 - np.sin(3*theta)

r2 = 1 + np.cos(theta)

ax = plt.subplot(111, polar=True, # add subplot in polar coordinates

axisbg='Azure') # background colour

ax.set_rmax(2.2) # r maximum value

ax.grid(True) # add the grid

ax.plot(theta, r1,

color='Tomato', # line colour

ls='--', # line style

lw=3, # line width

label='a 3-fold curve') # label

ax.plot(theta, r2,

color='purple',

linewidth=3,

ls = '-',

label = 'a cardioid')

ax.legend(loc="lower right") # legend location

titlefont = {

'family' : 'serif',

'color' : 'black',

'weight' : 'bold',

'size' : 16,

}

ax.set_title("A plot in polar coordinates", # title

va='bottom', # some space below the title

fontdict = titlefont # set the font properties

)

grid()

show()

#I am getting a separate Cartesian image + a polar image while what I need is both the things in a single image

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值