Plots.jl is a non-traditional plotting library
Plots.jl uses other plotting libraries as backends
To switch backends, you simply use the name of the library: https://juliaplots.github.io/backends/
using Plots
pyplot() # Turns on the PyPlot backend
plot(rand(4,4))
gr()
plot(rand(4,4))
plotly()
plot(rand(4,4))
The attributes work with each of the backends: https://juliaplots.github.io/attributes/
Compatibility of attributes is found in this chart: https://juliaplots.github.io/supported/
I find it easiest to use this page to find the right attributes: https://juliaplots.github.io/examples/pyplot/
pyplot()
plot(rand(4,4),title="Test Title",label=["First" "Second" "Third" "Fourth"])
gr()
plot(rand(4,4),title="Test Title",label=["First" "Second" "Third" "Fourth"])
plotly()
plot(rand(4,4),title="Test Title",label=["First" "Second" "Third" "Fourth"])
Any plot can be animated
# initialize the attractor
n = 1500
dt = 0.02
σ, ρ, β = 10., 28., 8/3
x, y, z = 1., 1., 1.
# initialize a 3D plot with 1 empty series
plt = path3d(1, xlim=(-25,25), ylim=(-25,25), zlim=(0,50),
xlab = "x", ylab = "y", zlab = "z",
title = "Lorenz Attractor", marker = 1)
# build an animated gif, saving every 10th frame
@gif for i=1:n
global x,y,z,σ
dx = σ*(y - x) ; x += dt * dx
dy = x*(ρ - z) - y ; y += dt * dy
dz = x*y - β*z ; z += dt * dz
push!(plt, x, y, z)
end every 10
Recipes are abstract instructions for how to "build a plot" from data. There are multiple kinds of recipes. In execution order:
Since these extend Plots.jl itself, all of Plots.jl is accessible from the plotting commands that these make, and these recipes are accessible from each other.
[Series recipes are used to extend the compatibility of backends itself!]
using DifferentialEquations
sol = solve(ODEProblem((u,p,t)->1.01u,0.5,(0.0,1.0)))
@show typeof(sol)
gr()
plot(sol,title="The Attributes Still Work")
StatsPlots provides a type recipe for how to read DataFrames, and a series recipe marginalhist
which puts together histograms into a cohesive larger plot
using RDatasets, StatPlots, Plots
iris = dataset("datasets","iris")
marginalhist(iris, :PetalLength, :PetalWidth)
M = randn(1000,4)
M[:,2] += 0.8sqrt(abs(M[:,1])) - 0.5M[:,3] + 5
M[:,3] -= 0.7M[:,1].^2 + 2
corrplot(M, label = ["x$i" for i=1:4])
import RDatasets
pyplot()
singers = RDatasets.dataset("lattice","singer")
violin(singers,:VoicePart,:Height,marker=(0.2,:blue,stroke(0)))
boxplot!(singers,:VoicePart,:Height,marker=(0.3,:orange,stroke(2)))
A series type allows you to define an entirely new way of visualizing data into backends.
groupedbar(rand(10,3), bar_position = :dodge, bar_width=0.7)
gr()
groupedbar(rand(10,3), bar_position = :dodge, bar_width=0.7)
Make a beautiful plot of your regression:
plot!
) to add the linear regression line over the scatter plotx
and y
axis