Python Forum
showing only desired part of a plot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
showing only desired part of a plot
#1
Hi,
I do simply have a plot but I need to show only a specific part of that plot. When I run the code below, it shows all possible results but I need only the part between y=-3 and y=3 also x=-3 and x=3.
If you can help me I will be very appreciated.

import numpy as np
import matplotlib.pyplot as plt
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

#plotting
plt.plot(x,z,color="red")
plt.show()
Reply
#2
You can use the xlim and ylim plot functions for that.

Add the following before your plt.plot() statement.
plt.xlim(-3, 3)
plt.ylim(-3, 3)
https://www.pythonprogramming.in/how-to-...otlib.html
"So, brave knights, if you do doubt your courage or your strength, come no further, for death awaits you all with nasty, big, pointy teeth!" - Tim the Enchanter
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Json filter is not capturing desired key/element mrapple2020 1 1,120 Nov-24-2022, 09:22 AM
Last Post: ibreeden
  how can I display only desired items? 3lnyn0 5 2,021 Dec-25-2021, 06:49 PM
Last Post: menator01
  ERROR: importing desired module mbgamer28 0 1,673 Apr-05-2021, 07:46 PM
Last Post: mbgamer28
  Not rounding to desired decimal places? pprod 2 2,542 Mar-05-2021, 11:11 AM
Last Post: pprod
  How to plot intraday data of several days in one plot mistermister 3 2,897 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  Why this code not getting desired output ? MDRI 2 2,522 Sep-18-2020, 02:11 AM
Last Post: MDRI
  [Beginner] Code is not producing desired result fakej171 2 2,422 Mar-21-2020, 10:26 AM
Last Post: buran
  Not Getting the Desired value using json.dumps saurabh210 0 1,498 Feb-03-2020, 06:48 PM
Last Post: saurabh210
  How to plot vertically stacked plot with same x-axis and SriMekala 0 1,917 Jun-12-2019, 03:31 PM
Last Post: SriMekala
  Code isn't working in several IDE's when other people are getting desired output. SuperSymmetry 1 2,547 Jul-22-2017, 07:03 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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