First, load the package
In [ ]:
using Plots
Then we choose a backend. The options are
I personally alternate between gr or plotlyjs. To be able to use a backend, you first need to install the package corresponding to the backend. Sometimes, especially with plotlyjs, dependencies need to be wrangled.
In [ ]:
gr()
Now let's just create a simple plot.
In [ ]:
plot(1:10,(1:10).^2)
To alter a plot that you've created, append the ! exclamation sign to the command. In julia ! alters an existing object.
In [ ]:
plot!(1:10,1:10)
Calling pyplot(show=true) opens the plot in a new window. For the other backends, it doesn't open in a new window. At least for me.
Calling gui() is also supposed to open up an interactive window, but that doesn't seem to work for me either...
In [ ]:
pyplot(show=true)
plot(1:10,1:10)
Plots supports many export formats, and automatically detects what one to use by the filename. Now, we can simply save a figure with
In [ ]:
savefig("testsave.svg")
I often save plotlyjs output as html for interactivity on the gh-pages for my blog. By default, savefig outputs the html file with a call to a script on the local computer. The script is part of the local plotlyjs installation. I would the script to be local if I was working offline. But when I'm giving the script to be hosted online, I need an online script. Open the file in a text editor, and replace the local script with this one:
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
In [ ]: