Python Forum
showing all parts in the boundaries when plotting
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
showing all parts in the boundaries when plotting
#1
Hi everybody,
When I was plotting according to the code below, it gives the result between -60 and 20 on the x-axis but I want only the part between -3 and 3.
I tried
ax = plt.gca()
ax.set_ylim([-3,3])
ax.set_xlim([-3,3])
However, this doesn't show after when the plot comes out from the boundaries but I want all the parts between -3 and 3.
Please help me guys



import numpy as np
import matplotlib.pyplot as plt
from sympy import *
import sympy as sp
from scipy import integrate


def f(t,r):
    theta,x,z=r
    ftheta=(-1/2)*(np.cos(x)*np.cos(z)+np.sin(theta)/100)
    fx=0.5*np.sin(theta)-(1/2)*np.cos(x)*np.sin(z)
    fz=0.5*np.cos(theta)+(1/2)*np.sin(x)*np.cos(z)
    return ftheta,fx, fz

sol=integrate.solve_ivp(f,(0,2000),(np.pi/4,-np.pi/2,-np.pi/2), t_eval=np.linspace(0,2000,100000))
theta,x,z=sol.y
plt.plot(x,z,color="red")
plt.axis("scaled")
plt.xlabel("x")
plt.ylabel("z")
plt.show()
Reply
#2
Hello
could "xlim" and "ylim" plot properties be of help? Try it like this:
https://www.pythonprogramming.in/how-to-...otlib.html
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,497 Apr-05-2022, 06:18 AM
Last Post: C0D3R

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020