Как указать на графике, где начинается линия? - PullRequest
0 голосов
/ 30 декабря 2018

Я хотел бы указать начальную точку графика - где линия началась.Это мой код

import numpy as np
from scipy.integrate import odeint
from numpy import sin, cos, pi, array
import matplotlib
from matplotlib import rcParams
import matplotlib.pyplot as plt
from pylab import figure, axes, title, show
import xlsxwriter

def deriv(z, t):
    l = 0.3    #unextended length of the spring, in m
    m = 1       #mass of the bob, in kg
    k = 1      #spring constant, in Nm^-1
    g = 9.81    #gravitational acceleration, in ms^-2
    
    x, y, dxdt, dydt = z
    
    dx2dt2 = (l+x)*(dydt)**2 - k/m*x + g*cos(y)
    dy2dt2 = (-g*sin(y) - 2*(dxdt)*(dydt))/(l+x)
            #equations of motion
    
    return np.array([dxdt, dydt, dx2dt2, dy2dt2])

init = array([0.3, pi/2, 0.0, 2])
            #initial conditions (x, y, xdot, ydot)

time = np.linspace(0, 100, 10000)
            #time intervals (start, end, number of intervals)

sol = odeint(deriv, init, time)
            #solving the equations of motion

x = sol[:,0]
y = sol[:,1]

l = 0.3    #unextended length of the spring, in m
 
n = (l+x) * sin(y)
u = -(l+x) * cos(y)
            #converting x and y to Cartesian coordinates

plt.plot(n,u)
plt.xlabel('$n$ (m)')
plt.ylabel('$u$ (m)')
plt.title('$n$ versus $u$ for 'r'$\theta_0 = \frac{\pi}{2}+0.001$')
plt.show()
, который генерирует этот график: enter image description here Однако неясно, где линия фактически началась (где-то в верхнем правом углу, я думаю, рядом с тем, где она закончилась).Есть ли способ, которым я могу добавить ярко окрашенную точку в начальную точку, не специфичную только для этого графика (т.е. чтобы я мог воспроизвести на других графиках с другими условиями)?

Спасибо!

1 Ответ

0 голосов
/ 30 декабря 2018

Построение первой точки можно сделать, добавив plt.plot (n [0], u [0], '*') к вашему коду, см. Ниже.

Полная документация для Функция сюжета (спасибо за комментарий в основном кислородом), чтобы лучше понять, как можно изменить цвет, размер и форму точки.

output

from scipy.integrate import odeint
from numpy import array, linspace, sin, cos, pi, array
from matplotlib import rcParams
import matplotlib.pyplot as plt

def deriv(z, t):
    l = 0.3    #unextended length of the spring, in m
    m = 1       #mass of the bob, in kg
    k = 1      #spring constant, in Nm^-1
    g = 9.81    #gravitational acceleration, in ms^-2

    x, y, dxdt, dydt = z

    dx2dt2 = (l+x)*(dydt)**2 - k/m*x + g*cos(y)
    dy2dt2 = (-g*sin(y) - 2*(dxdt)*(dydt))/(l+x)
            #equations of motion

    return array([dxdt, dydt, dx2dt2, dy2dt2])

init = array([0.3, pi/2, 0.0, 2])
            #initial conditions (x, y, xdot, ydot)

time = linspace(0, 100, 10000)
            #time intervals (start, end, number of intervals)

sol = odeint(deriv, init, time)
            #solving the equations of motion

x = sol[:,0]
y = sol[:,1]

l = 0.3    #unextended length of the spring, in m

n = (l+x) * sin(y)
u = -(l+x) * cos(y)
            #converting x and y to Cartesian coordinates

plt.plot(n,u)
plt.plot(n[0], u[0], '*')
plt.xlabel('$n$ (m)')
plt.ylabel('$u$ (m)')
plt.title('$n$ versus $u$ for 'r'$\theta_0 = \frac{\pi}{2}+0.001$')
plt.show()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...