Python Forum
showing all parts in the boundaries when plotting - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: showing all parts in the boundaries when plotting (/thread-28231.html)



showing all parts in the boundaries when plotting - grknkilicaslan - Jul-10-2020

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()



RE: showing all parts in the boundaries when plotting - j.crater - Jul-11-2020

Hello
could "xlim" and "ylim" plot properties be of help? Try it like this:
https://www.pythonprogramming.in/how-to-set-axis-limits-in-matplotlib.html