Python Forum
first time in python - 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: first time in python (/thread-22158.html)



first time in python - TDW5 - Nov-01-2019

Hello,

Anyone who can tell me how to plot something like this:
f = f(x)
g = function with variable f = g(f)
h = function of g = h(g)

T = k(h(g(f)))

plot T(x)
Thanks!

E.g. f = sin(x)
g = 5 + f**2
h = 1 - log(g)
T = f - g**2 + sin(h)


RE: first time in python - jefsummers - Nov-01-2019

By algebra substitution you are wanting to plot the function
sin(x)-(5+sin(x)**2)**2 + sin(1-log(5+sin(x)**2)). Correct?

My opinion, YMMV, is to use matplotlib and I find it easiest with Pandas
BTW - around here you will find that folks want you to start, try doing things, and then post a question about how far you got and what needs to be fixed. What I am posting here should cause you to think and give you leads about what to look at next - docs for Pandas and docs for matplotlib, for example. That plus a few youtube videos and you should be on your way.

import pandas as pd
import matplotlib.pyplot as plt
import math

def fn_generator(x) :
    return math.sin(x)-(5+math.sin(x)**2)**2 + math.sin(1-math.log(5+math.sin(x)**2))
    
data = []
for x in range(1,10000):
    data.append([x,fn_generator(x/100)])

df = pd.DataFrame(data)
df.columns = ['count','amount']

df.plot(kind="line", x='count', y='amount')