Error in plotting

I’m trying to plotting something. This is my code

x = 1:20
y = m1[1,:]
plot(x,y)

Here y is a vector. And I want to plot the elements of this vector with x values = [1:20]. And I got the error

MethodError: objects of type Plots.Plot{Plots.GRBackend} are not callable
Stacktrace:
[1] top-level scope
@ In[412]:3
[2] eval
@ ./boot.jl:373 [inlined]
[3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1196

How to fix this error?

I assume that you saved a previous plot under the variable name plot. But that happened to overwrite the plot function so now Julia complains that you can’t call a Plot object. You could probably get it back by doing plot = Plots.plot.

I used Plots.scatter(x,y) and I get points. But what I want is a line. There is no plot variable name plot.

Aren’t we debugging why plot(x, y) didn’t work? You said nothing about scatter :slight_smile:

plot(x,y) didn’t work so I tried Plots.scatter(x,y) :rofl:

And I tried plot = Plots.plot, got BoundsError: attempt to access 20-element UnitRange{Int64} at index [1:35] error.

Ok now that is really weird, why is it even indexing anything? Id just restart the session and try again, I see no reason why your first code shouldn’t work

y is a 35-element vector. Is this the reason?

Oh so you got the error after you used the reassigned plot, ok now it makes sense. Yes you can’t plot two vectors of different length, x is 20 long and y 35. What did you expect would be displayed in that case? :slight_smile:

Well, what I want is similar with the plot below, but I want a line connecting these points in the plot.
Screen Shot 2022-07-08 at 4.53.31 PM

Instead of Plots.scatter(x,y) (creates a scatterplot), try Plots.plot(x,y) (creates a lineplot).