Problems with Julia storyline array

Coming from Matlab, I try my best to understand why the following does not work:

plot(x=rand(10),y=rand(10)) 

Correctly displays the graph.

 x=rand(10) y=rand(10) plot(x,y) 

causes an error:

ERROR: plot does not have a suitable graph for the method (:: Array (Float64,1), :: Array (Float64,1))

I would be very grateful if someone would explain to me why embedding the code in the plot line leads to the result, but the definition of variables leads to an error in advance. Logic says that they should give the same result.

I am using Julia v 0.3.1 and downloaded Gadfly as a charting tool.

+5
source share
2 answers

In the first case, you use the keyword argument syntax without assigning x and y to the variables (the value = inside function calls is special). To get the same effect in the second case, you should use

 x=rand(10) y=rand(10) plot(x=x,y=y) 

which passes the value in the variable x in the argument of the keyword x - plot , and the value in the variable y in the argument of the keyword y .

+8
source

In case you did not. Write this before your code:

 using plots plyplot() 
0
source

Source: https://habr.com/ru/post/1203603/


All Articles