Как построить уравнение с разными значениями функции греха? - PullRequest
0 голосов
/ 03 августа 2020

Я пытаюсь построить функцию так, как показано на рисунке по ссылке:

enter image description here

The equation in which this plot is based on is: y= sin^2θ x /(e^x +1)

I have previously plotted the equation above without the sine function, using the following code:

# Generate some data.
x = np.logspace(-1, 3, 100)
y= x * 1/ (np.exp(x) + 1)


plt.loglog(x, y)
plt.autoscale(enable=True, axis='x', tight=True) # optionally set a tight x-axis
#adding labels to axis
plt.xlabel('y=E/T')
plt.ylabel('$f_s$')
plt.show()

But how can I plot this function with a varying sin function. I have tried applying what was used in the following link but I don't understand the code: Как преобразовать числа в цветовую шкалу в matplotlib?

Я новичок в python, и в коде почти нет описания.

Я также пытался применить метод, показанный в Как мне построить функцию с разными значениями параметра на одном и том же графике в gnuplot 4.4? но я продолжаю получать то же сообщение об ошибке, " Неверный синтаксический шаблон E "

1 Ответ

1 голос
/ 03 августа 2020
theta = [...] # your values of theta you'd like to plot
x = np.linspace(-1, 3, 100) # Or np.logspace, as you want. You'll have to change the parameters though, if you want to display properly
y = x / (np.exp(x)+1)

for t in theta :
  plt.plot(x, np.sin(2*t)*y, label = 'theta = %s' % t)
plt.legend()
plt.show()

Результат для theta = [1,2,3]:

image1

If you want to display a colormap, you can do this (code taken from здесь ):

import matplotlib
norm = matplotlib.colors.Normalize(vmin=np.min(theta), vmax=np.max(theta))
c_m = matplotlib.cm.cool
s_m = matplotlib.cm.ScalarMappable(cmap=c_m, norm=norm)
s_m.set_array([])

for t in theta :
  plt.plot(x, np.sin(2*t)*y, color=s_m.to_rgba(t))

plt.colorbar(s_m)
plt.show()

Результат:

imageColormap

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...