regend_kura February 2016
### Drawing a figure from complex formula

I would like to draw a figure from the formula to the figure. The following code I wrote seems wrong. How should I fix it?

```
import pylab
import numpy as np
import matplotlib.pyplot as plt
plt.plot( [0])
plt.legend()
x = np.linspace(0,120,121)
y = 2*20 / 500*("x")
plt.plot(x,y)
plt.xlim([0,120])
plt.ylim([0.0001,1])
plt.yscale("log")
plt.title("Graph Synchronization")
plt.xlabel("p")
plt.ylabel("lamda-min")
plt.show()
```

Neil_UK February 2016

x = np.linspace ... is creating an x array

I suspect that you want to create a y array, and then plot y against x.

Using numpy, there is no need to do the python loop thing for x_elem in x:, as numpy lets you work directly with arrays.

y = 2*20 / 500*x

will create a y array of the same length as x.

Then try the rest of your plot program.

Dano February 2016

- You are dividing by an integer. Doing this performs floor division in python2. insert
`from __future__ import division`

on the first line of your program. - also, let
`y = 2*20 / 500*x`

I tested your code and these changes fixed everything

Asked in February 2016

Viewed 1,374 times

Voted 5

Answered 2 times

Viewed 1,374 times

Voted 5

Answered 2 times