cj wyett
cj wyett

Reputation: 152

Plotting the columns of a 2D array

Say I have a 2D array. The first column contains x values and the second contains y values.

arr = [1 0.1; 2 0.2]

Outputs:

2×2 Array{Float64,2}:
 1.0  0.1
 2.0  0.2

If I want to plot the columns against each other I do so with

using Plots    
plot(arr[:,1], arr[:,2])

enter image description here

Is there a cleaner way to do this?

Using plot(arr) outputs:enter image description here

Upvotes: 2

Views: 1101

Answers (1)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42244

If you want to reference arr only once you could do:

plot(eachcol(arr)...)

Upvotes: 1

Related Questions