Thursday, October 17, 2019

Python: Plotting graphs

Plot  graph g(t) = (t^2, t^3 - t) for t(-2,2)

import matplotlib.pyplot as mp
import numpy as np
#Domain
t = np.arange(-2,2,0.001)
# create lists x and y which have all the values of x and y for the given domain
x = []
y = []

for i in t:
  x = x + [i*i]
  y = y + [i*i*i -3*i]
mp.plot(x, y)
  #mp.show()

# naming the x axis
mp.xlabel('x - axis')
# naming the y axis
mp.ylabel('y - axis')

# giving a title to my graph
mp.title('')

# function to show the plot
mp.show()

Output:
You can practice python at colab


No comments:

Post a Comment

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...