Skip to main content
Mathematics LibreTexts

11.4: Plotting Data

  • Page ID
    63931
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    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)

    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)

    and we can plot both points and lines with:

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

     


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

    • Was this article helpful?