Skip to content

Commit

Permalink
ploting 2d graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipul-Cariappa committed Dec 16, 2022
1 parent 9821f6b commit 62068e7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions graph_2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from datetime import datetime
import matplotlib.pyplot as plt
import numpy as np
from math import *

string = input("Enter Function to be Plot\n\tf(x) = ")

func_str = "lambda x: " + string.replace("^", "**")
func = eval(func_str)

x = np.linspace(-10, 10, 100)
y = np.apply_along_axis(np.vectorize(func), 0, x)

plt.plot(x, y)
plt.ylabel(string)
plt.xlabel("x")
plt.show()
# file_name = str(datetime.now()).split(".")[0].replace(":", "-") + ".png"
# plt.savefig(file_name, bbox_inches='tight')

0 comments on commit 62068e7

Please sign in to comment.