plot to create a new plot object, and
plot! to add to an existing one:
plot(args...; kw...) # creates a new Plot, and set it to be the `current` plot!(args...; kw...) # modifies Plot `current()` plot!(plt, args...; kw...) # modifies Plot `plt`
The graphic is not shown implicitly, only when "displayed". This will happen automatically when returned to a REPL prompt or to an IJulia cell. There are many other options as well.
Input arguments can take many forms. Some valid examples:
plot() # empty Plot object plot(4) # initialize with 4 empty series plot(rand(10)) # 1 series... x = 1:10 plot(rand(10,5)) # 5 series... x = 1:10 plot(rand(10), rand(10)) # 1 series plot(rand(10,5), rand(10)) # 5 series... y is the same for all plot(sin, rand(10)) # y = sin.(x) plot(rand(10), sin) # same... y = sin.(x) plot([sin,cos], 0:0.1:π) # 2 series, sin.(x) and cos.(x) plot([sin,cos], 0, π) # sin and cos on the range [0, π] plot(1:10, Any[rand(10), sin]) # 2 series: rand(10) and map(sin,x) plot(dataset("Ecdat", "Airline"), :Cost) # the :Cost column from a DataFrame... must import StatsPlots
Keyword arguments allow for customization of the plot, subplots, axes, and series. They follow consistent rules as much as possible, and you'll avoid common pitfalls if you read this section carefully:
- Many arguments have aliases which are replaced during preprocessing.
cis the same as
mis the same as
marker, etc. You can choose a verbosity that you are comfortable with.
- There are some special arguments which magically set many related things at once.
- If the argument is a "matrix-type", then each column will map to a series, cycling through columns if there are fewer columns than series. In this sense, a vector is treated just like an "nx1 matrix".
- Many arguments accept many different types... for example the color (also markercolor, fillcolor, etc) argument will accept strings or symbols with a color name, or any Colors.Colorant, or a ColorScheme, or a symbol representing a ColorGradient, or an AbstractVector of colors/symbols/etc...