简体   繁体   中英

I got this error: "f x and y must have same first dimension but have shapes python"

import sympy as sy
import matplotlib.pyplot as plt
import numpy as np

x = sy.symbols('x')
print("function:")
f = str(input())

#
df1 = sy.diff(f)
df2 = sy.diff(df1)
df3 = sy.diff(df2)

#Volvemos estas funciones simbolicas a numericas.
nf = sy.lambdify( x, f, "numpy")
ndf1 = sy.lambdify( x, df1, "numpy")
ndf2 = sy.lambdify( x, df2, "numpy")
ndf3 = sy.lambdify( x, df3, "numpy")

#
print("domain")
a = int(input())
b = int(input())
z = np.arange(a, b)

plt.plot(z,nf, color='purple', label='nf', marker=',')
plt.show()

Your issue is that you are creating a function and plotting only the function call. You need to apply the function to your data so you can then plot it. So all you have to do is change your plotting line to the following.

plt.plot(z,nf(z), color='purple', label='nf', marker=',')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM