11.4: Plotting Data

Scientific Computing · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under not declared, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    11.4: Plotting Data

    Here's some preliminary commands to run if they haven't been yet. 

    using Pkg; Pkg.add("Plots")
       Updating registry at `/srv/julia/pkg/registries/General`
      Resolving package versions...
    No Changes to `~/Project.toml`
    No Changes to `~/Manifest.toml`
    

    And for this section, we will need to let julia know to use the Plots package:

    using Plots
     

    We will want to produce plots of datasets, we'll start with just some random data.  The following produces the values 1 to 10 for x and random integers between 1 and 10 for y:  

    x=1:10
    y=rand(1:10,10)
    10-element Array{Int64,1}:
     1
     6
     3
     4
     1
     3
     3
     9
     8
     1

    The following will produce a scatter plot of the data, where each point is plotted as a point.  

    scatter(x,y)
    Illustration

    If we wanted the data to be plotted with lines connecting the points, we use the same plot command as we did above.  

    plot(x,y)
    Illustration

    and we can plot both points and lines with:

    plot(x,y,seriestype=[:scatter,:line])
    Illustration

     


    11.4: Plotting Data is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.