使用python在2dci上绘制垂直矢量

2024-09-24 06:31:21 发布

您现在位置:Python中文网/ 问答频道 /正文

在我的代码中,我假设2D圆是一个类似于地球但蓝色的行星。我想在蓝色圆圈的边上画出两个相互垂直的向量a,u,r,但是我不知道如何把垂直向量a,u,r放在圆的顶部或底部。What I want to plot in pythonnot circular?quiver plot

下面是我使用的代码:

    # Importing modules
    import numpy as np
    import matplotlib.pyplot as plt


    g=9.81
    Mmoon=7.3477e22 #mass of Moon
    Mearth=5.972e24 #mass of Earth

    R_min=356.5e6 #Perigee
    R_max=406.7e6 #Apogee
    R_avg = 0.5*(R_min + R_max)
    r = 6.3781e6 #radius of Earth

    theta=np.linspace(-1*np.pi,1*np.pi,180)

    a_R=3*g*(Mmoon/Mearth)*((r/(R_avg))**3)*np.cos(theta)   
    #acceleration vector

    a_h=3*g*(Mmoon/Mearth)*((r/(R_avg))**3)*np.cos(theta)*np.sin(theta)         
    #tangential acceleration vector
    a_r=3*g*(Mmoon/Mearth)*((r/(R_avg))**3)*np.cos(theta)*np.cos(theta)         
    #perpendicular acceleration vector

    plt.quiver([0,0 ], [0,0], [2,-2], [-4, -2], angles='xy',         
    scale_units='xy', scale=1)
    plt.xlim(-10,10)
    plt.ylim(-10,10)

    earth = plt.Circle((0.5, 0.5), 0.2, color='blue')  # (x_pos, y_pos), rad

    fig, ax = plt.subplots() # note we must use plt.subplots, not 
    plt.subplot
    #(or if you have an existing figure)
    fig = plt.gcf()
    ax = fig.gca()
    ax.add_artist(earth)

任何帮助都将不胜感激!!在


Tags: of代码npfigpltcosax蓝色
2条回答

Circle命令在代码中什么也不做。为什么不使用scatter圆形标记?在

plt.scatter(0., 0., 100, color='blue')

这里不使用散点是有意义的,因为这需要计算散点在数据单位中的点数。用圆圈代替是可以的。在

箭头被放置在根据月球轨道R_avg的位置。它们的长度在这里是任意的,但是你当然可以随意改变它。在

import matplotlib.pyplot as plt

R_min=356.5e6 #Perigee
R_max=406.7e6 #Apogee
R_avg = 0.5*(R_min + R_max)
r = 6.3781e6 #radius of Earth

ax = plt.gca()
ax.set_aspect("equal")
i = 0

# create arrows on moon orbit, both one orbit radius in length to both directions
ax.quiver([0,0], [R_avg,R_avg], [1,0], [0, 1], angles='xy',         
          scale_units='xy', scale=1./R_avg)

# create earth and moon orbit
earth = plt.Circle((0,0),r)
orbit = plt.Circle((0,0),R_avg, fill=False, color="crimson")
ax.add_patch(earth)
ax.add_patch(orbit)
ax.autoscale_view()
ax.margins(1)

plt.show()

enter image description here

相关问题 更多 >