diff --git a/README.md b/README.md index b1de2d59..ea6ba112 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,10 @@ xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims) ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims) xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v) yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = v) +xflip!(flip::Bool = true) = plot!(xflip = flip) +yflip!(flip::Bool = true) = plot!(yflip = flip) +xaxis!(args...) = plot!(xaxis = args) +yaxis!(args...) = plot!(yaxis = args) annotate!(anns) = plot!(annotation = anns) ``` @@ -278,11 +282,25 @@ Type | Aliases __Tip__: You can see the default value for a given argument with `default(arg::Symbol)`, and set the default value with `default(arg::Symbol, value)` or `default(; kw...)`. For example set the default window size and whether we should show a legend with `default(size=(600,400), leg=false)`. -__Tip__: When plotting multiple lines, you can set all series to use the same value, or pass in an array to cycle through values. Example: +__Tip__: There are some helper arguments you can set: `xaxis`, `yaxis`, `line`, `marker`, `fill`. These go through special preprocessing to extract values into individual arguments. The order doesn't matter, and if you pass a single value it's equivalent to wrapping it in a Tuple. Examples: + +``` +plot(y, xaxis = ("mylabel", :log, :flip, (-1,1))) # this sets the `xlabel`, `xscale`, `xflip`, and `xlims` arguments automatically +plot(y, line = (:bar, :blue, :dot, 10)) # this sets the `linetype`, `color`, `linestyle`, and `linewidth` arguments automatically +plot(y, marker = (:rect, :red, 10)) # this sets the `markershape`, `markercolor`, and `markersize` arguments automatically +plot(y, fill = (:green, 10)) # this sets the `fillcolor` and `fillrange` arguments automatically + # Note: `fillrange` can be: + a number (fill to horizontal line) + a vector of numbers (different for each data point) + a tuple of vectors (fill a band) +``` + +__Tip__: When plotting multiple lines, you can set all series to use the same value, or pass in a matrix to cycle through values. Example: ```julia -plot(rand(100,4); color = [:red, RGB(0,0,1)], # lines 1 and 3 are red, lines 2 and 4 are blue +plot(rand(100,4); color = [:red RGB(0,0,1)], # (Matrix) lines 1 and 3 are red, lines 2 and 4 are blue axis = :auto, # lines 1 and 3 are on the left axis, lines 2 and 4 are on the right + markershape = [:rect, :star1] # (Vector) ALL lines are passed the vector [:rect, :star1] width = 5) # all lines have a width of 5 ``` diff --git a/docs/readme_template.md b/docs/readme_template.md index b6b11889..4db4c08b 100644 --- a/docs/readme_template.md +++ b/docs/readme_template.md @@ -174,6 +174,10 @@ xlims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(xlims = lims) ylims!{T<:Real,S<:Real}(lims::Tuple{T,S}) = plot!(ylims = lims) xticks!{T<:Real}(v::AVec{T}) = plot!(xticks = v) yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = v) +xflip!(flip::Bool = true) = plot!(xflip = flip) +yflip!(flip::Bool = true) = plot!(yflip = flip) +xaxis!(args...) = plot!(xaxis = args) +yaxis!(args...) = plot!(yaxis = args) annotate!(anns) = plot!(annotation = anns) ``` @@ -196,11 +200,25 @@ Markers: __Tip__: You can see the default value for a given argument with `default(arg::Symbol)`, and set the default value with `default(arg::Symbol, value)` or `default(; kw...)`. For example set the default window size and whether we should show a legend with `default(size=(600,400), leg=false)`. -__Tip__: When plotting multiple lines, you can set all series to use the same value, or pass in an array to cycle through values. Example: +__Tip__: There are some helper arguments you can set: `xaxis`, `yaxis`, `line`, `marker`, `fill`. These go through special preprocessing to extract values into individual arguments. The order doesn't matter, and if you pass a single value it's equivalent to wrapping it in a Tuple. Examples: + +``` +plot(y, xaxis = ("mylabel", :log, :flip, (-1,1))) # this sets the `xlabel`, `xscale`, `xflip`, and `xlims` arguments automatically +plot(y, line = (:bar, :blue, :dot, 10)) # this sets the `linetype`, `color`, `linestyle`, and `linewidth` arguments automatically +plot(y, marker = (:rect, :red, 10)) # this sets the `markershape`, `markercolor`, and `markersize` arguments automatically +plot(y, fill = (:green, 10)) # this sets the `fillcolor` and `fillrange` arguments automatically + # Note: `fillrange` can be: + a number (fill to horizontal line) + a vector of numbers (different for each data point) + a tuple of vectors (fill a band) +``` + +__Tip__: When plotting multiple lines, you can set all series to use the same value, or pass in a matrix to cycle through values. Example: ```julia -plot(rand(100,4); color = [:red, RGB(0,0,1)], # lines 1 and 3 are red, lines 2 and 4 are blue +plot(rand(100,4); color = [:red RGB(0,0,1)], # (Matrix) lines 1 and 3 are red, lines 2 and 4 are blue axis = :auto, # lines 1 and 3 are on the left axis, lines 2 and 4 are on the right + markershape = [:rect, :star1] # (Vector) ALL lines are passed the vector [:rect, :star1] width = 5) # all lines have a width of 5 ``` diff --git a/docs/winston_examples.md b/docs/winston_examples.md index 1ca80f7a..e31cb39c 100644 --- a/docs/winston_examples.md +++ b/docs/winston_examples.md @@ -1,10 +1,10 @@ # Examples for backend: winston -- Supported arguments: `annotation`, `color`, `fillto`, `group`, `label`, `legend`, `linestyle`, `linetype`, `marker`, `markercolor`, `markersize`, `nbins`, `reg`, `show`, `size`, `title`, `width`, `windowtitle`, `x`, `xlabel`, `y`, `ylabel` +- Supported arguments: `annotation`, `color`, `color_palette`, `fillrange`, `fillcolor`, `group`, `label`, `legend`, `linestyle`, `linetype`, `linewidth`, `markershape`, `markercolor`, `markersize`, `nbins`, `reg`, `show`, `size`, `title`, `windowtitle`, `x`, `xlabel`, `xlims`, `y`, `ylabel`, `ylims`, `xscale`, `yscale` - Supported values for axis: `:auto`, `:left` - Supported values for linetype: `:none`, `:line`, `:path`, `:sticks`, `:scatter`, `:hist`, `:bar` -- Supported values for linestyle: `:solid`, `:dash`, `:dot`, `:dashdot` -- Supported values for marker: `:none`, `:ellipse`, `:rect`, `:diamond`, `:utriangle`, `:dtriangle`, `:cross`, `:xcross`, `:star1` +- Supported values for linestyle: `:auto`, `:solid`, `:dash`, `:dot`, `:dashdot` +- Supported values for marker: `:none`, `:auto`, `:rect`, `:ellipse`, `:diamond`, `:utriangle`, `:dtriangle`, `:cross`, `:xcross`, `:star1` - Is `subplot`/`subplot!` supported? No ### Initialize @@ -19,14 +19,14 @@ winston() A simple line plot of the columns. ```julia -plot(rand(50,5),w=3) +plot(fakedata(50,5),w=3) ``` ![](../img/winston/winston_example_1.png) ### Functions -Plot multiple functions. You can also put the function first. +Plot multiple functions. You can also put the function first, or use the form `plot(f, xmin, xmax)` where f is a Function or AbstractVector{Function}. ```julia plot(0:0.01:4π,[sin,cos]) @@ -36,32 +36,34 @@ plot(0:0.01:4π,[sin,cos]) ### -You can also call it with plot(f, xmin, xmax). +Or make a parametric plot (i.e. plot: (fx(u), fy(u))) with plot(fx, fy, umin, umax). ```julia -plot([sin,cos],0,4π) +plot(sin,(x->begin # /home/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 39: + sin(2x) + end),0,2π,line=4,leg=false,fill=(0,:orange)) ``` ![](../img/winston/winston_example_3.png) -### +### Colors -Or make a parametric plot (i.e. plot: (fx(u), fy(u))) with plot(fx, fy, umin, umax). +Access predefined palettes (or build your own with the `colorscheme` method). Line/marker colors are auto-generated from the plot's palette, unless overridden. Set the `z` argument to turn on series gradients. ```julia -plot(sin,(x->begin # /home/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 33: - sin(2x) - end),0,2π,legend=false,fillto=0) +y = rand(100) +plot(0:10:100,rand(11,4),lab="lines",w=3,palette=:grays,fill=(0.5,:auto)) +scatter!(y,z=abs(y - 0.5),m=(10,:heat),lab="grad") ``` ![](../img/winston/winston_example_4.png) ### Global -Change the guides/background/limits/ticks. You can also use shorthand functions: `title!`, `xlabel!`, `ylabel!`, `xlims!`, `ylims!`, `xticks!`, `yticks!` +Change the guides/background/limits/ticks. Convenience args `xaxis` and `yaxis` allow you to pass a tuple or value which will be mapped to the relevant args automatically. The `xaxis` below will be replaced with `xlabel` and `xlims` args automatically during the preprocessing step. You can also use shorthand functions: `title!`, `xaxis!`, `yaxis!`, `xlabel!`, `ylabel!`, `xlims!`, `ylims!`, `xticks!`, `yticks!` ```julia -plot(rand(10),title="TITLE",xlabel="XLABEL",ylabel="YLABEL",background_color=RGB(0.2,0.2,0.2),xlim=(-3,13),yticks=0:0.1:1) +plot(rand(20,3),title="TITLE",xaxis=("XLABEL",(-5,30),0:2:20,:flip),yaxis=("YLABEL",:log10),background_color=RGB(0.2,0.2,0.2),leg=false) ``` ![](../img/winston/winston_example_5.png) @@ -73,17 +75,17 @@ Use the `axis` arguments. Note: Currently only supported with Qwt and PyPlot ```julia -plot(Vector[randn(100),randn(100) * 100]; axis=[:l,:r],ylabel="LEFT",yrightlabel="RIGHT") +plot(Vector[randn(100),randn(100) * 100]; axis=[:l :r],ylabel="LEFT",yrightlabel="RIGHT") ``` ![](../img/winston/winston_example_6.png) -### Vectors w/ pluralized args +### Arguments -Plot multiple series with different numbers of points. Mix arguments that apply to all series (singular... see `marker`) with arguments unique to each series (pluralized... see `colors`). +Plot multiple series with different numbers of points. Mix arguments that apply to all series (marker/markersize) with arguments unique to each series (colors). Special arguments `line`, `marker`, and `fill` will automatically figure out what arguments to set (for example, we are setting the `linestyle`, `linewidth`, and `color` arguments with `line`.) Note that we pass a matrix of colors, and this applies the colors to each series. ```julia -plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,c=[:red,:blue]) +plot(Vector[rand(10),rand(20)]; marker=(:ellipse,8),line=(:dot,3,[:black :orange])) ``` ![](../img/winston/winston_example_7.png) @@ -93,7 +95,7 @@ plot(Vector[rand(10),rand(20)]; marker=:ellipse,markersize=8,c=[:red,:blue]) Start with a base plot... ```julia -plot(rand(100) / 3,reg=true,fillto=0) +plot(rand(100) / 3,reg=true,fill=(0,:green)) ``` ![](../img/winston/winston_example_8.png) @@ -103,7 +105,7 @@ plot(rand(100) / 3,reg=true,fillto=0) and add to it later. ```julia -scatter!(rand(100),markersize=6,c=:blue) +scatter!(rand(100),markersize=6,c=:orange) ``` ![](../img/winston/winston_example_9.png) @@ -113,11 +115,11 @@ scatter!(rand(100),markersize=6,c=:blue) ```julia -types = intersect(supportedTypes(),[:line,:path,:steppre,:steppost,:sticks,:scatter]) +types = intersect(supportedTypes(),[:line,:path,:steppre,:steppost,:sticks,:scatter])' n = length(types) x = Vector[sort(rand(20)) for i = 1:n] y = rand(20,n) -plot(x,y,t=types,lab=map(string,types)) +plot(x,y,line=(types,3),lab=map(string,types),ms=15) ``` ![](../img/winston/winston_example_11.png) @@ -127,7 +129,7 @@ plot(x,y,t=types,lab=map(string,types)) ```julia -styles = setdiff(supportedStyles(),[:auto]) +styles = setdiff(supportedStyles(),[:auto])' plot(cumsum(randn(20,length(styles)),1); style=:auto,label=map(string,styles),w=5) ``` @@ -138,8 +140,8 @@ plot(cumsum(randn(20,length(styles)),1); style=:auto,label=map(string,styles),w= ```julia -markers = setdiff(supportedMarkers(),[:none,:auto]) -scatter(0.5:9.5,[fill(i - 0.5,10) for i = length(markers):-1:1]; marker=:auto,label=map(string,markers),ms=10) +markers = setdiff(supportedMarkers(),[:none,:auto])' +scatter(0.5:9.5,[fill(i - 0.5,10) for i = length(markers):-1:1]; marker=:auto,label=map(string,markers),ms=12) ``` ![](../img/winston/winston_example_13.png) @@ -149,7 +151,7 @@ scatter(0.5:9.5,[fill(i - 0.5,10) for i = length(markers):-1:1]; marker=:auto,la x is the midpoint of the bar. (todo: allow passing of edges instead of midpoints) ```julia -bar(randn(1000)) +bar(randn(999)) ``` ![](../img/winston/winston_example_14.png) diff --git a/img/supported/Plots.supportGraphArgs.png b/img/supported/Plots.supportGraphArgs.png index 77801b60..ce47043e 100644 Binary files a/img/supported/Plots.supportGraphArgs.png and b/img/supported/Plots.supportGraphArgs.png differ diff --git a/img/winston/winston_example_1.png b/img/winston/winston_example_1.png index b2fc313f..00f02402 100644 Binary files a/img/winston/winston_example_1.png and b/img/winston/winston_example_1.png differ diff --git a/img/winston/winston_example_11.png b/img/winston/winston_example_11.png index f1b80d23..c30b49e7 100644 Binary files a/img/winston/winston_example_11.png and b/img/winston/winston_example_11.png differ diff --git a/img/winston/winston_example_12.png b/img/winston/winston_example_12.png index 039997a2..1bb92879 100644 Binary files a/img/winston/winston_example_12.png and b/img/winston/winston_example_12.png differ diff --git a/img/winston/winston_example_13.png b/img/winston/winston_example_13.png index d5ada60a..26ff68df 100644 Binary files a/img/winston/winston_example_13.png and b/img/winston/winston_example_13.png differ diff --git a/img/winston/winston_example_14.png b/img/winston/winston_example_14.png index bb4bc9a9..1033d496 100644 Binary files a/img/winston/winston_example_14.png and b/img/winston/winston_example_14.png differ diff --git a/img/winston/winston_example_15.png b/img/winston/winston_example_15.png index 61072f7a..8a2c3742 100644 Binary files a/img/winston/winston_example_15.png and b/img/winston/winston_example_15.png differ diff --git a/img/winston/winston_example_2.png b/img/winston/winston_example_2.png index e039367b..c6c591af 100644 Binary files a/img/winston/winston_example_2.png and b/img/winston/winston_example_2.png differ diff --git a/img/winston/winston_example_20.png b/img/winston/winston_example_20.png index 6a9758d4..ec09ad75 100644 Binary files a/img/winston/winston_example_20.png and b/img/winston/winston_example_20.png differ diff --git a/img/winston/winston_example_3.png b/img/winston/winston_example_3.png index d088f844..a8e91248 100644 Binary files a/img/winston/winston_example_3.png and b/img/winston/winston_example_3.png differ diff --git a/img/winston/winston_example_4.png b/img/winston/winston_example_4.png index 85947a97..bdcbe434 100644 Binary files a/img/winston/winston_example_4.png and b/img/winston/winston_example_4.png differ diff --git a/img/winston/winston_example_5.png b/img/winston/winston_example_5.png index debe69a9..3415ac7b 100644 Binary files a/img/winston/winston_example_5.png and b/img/winston/winston_example_5.png differ diff --git a/img/winston/winston_example_6.png b/img/winston/winston_example_6.png index 05f1b60c..2e3a3890 100644 Binary files a/img/winston/winston_example_6.png and b/img/winston/winston_example_6.png differ diff --git a/img/winston/winston_example_7.png b/img/winston/winston_example_7.png index cc01cb4e..3f1271de 100644 Binary files a/img/winston/winston_example_7.png and b/img/winston/winston_example_7.png differ diff --git a/img/winston/winston_example_8.png b/img/winston/winston_example_8.png index a59694fe..3e7c5f84 100644 Binary files a/img/winston/winston_example_8.png and b/img/winston/winston_example_8.png differ diff --git a/img/winston/winston_example_9.png b/img/winston/winston_example_9.png index 34751cc4..cdfa12e2 100644 Binary files a/img/winston/winston_example_9.png and b/img/winston/winston_example_9.png differ diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index 19ad7430..77396503 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -505,7 +505,6 @@ end function Base.writemime(io::IO, ::MIME"image/png", plt::Plot{GadflyPackage}) gplt = getGadflyContext(plt.backend, plt) - @show plt.initargs setGadflyDisplaySize(plt.initargs[:size]...) Gadfly.draw(Gadfly.PNG(io, Compose.default_graphic_width, Compose.default_graphic_height), gplt) end diff --git a/src/backends/winston.jl b/src/backends/winston.jl index 9c304a9f..c15f290b 100644 --- a/src/backends/winston.jl +++ b/src/backends/winston.jl @@ -36,6 +36,7 @@ supportedArgs(::WinstonPackage) = [ # :axis, # :background_color, :color, + :color_palette, :fillrange, :fillcolor, # :foreground_color, @@ -132,13 +133,12 @@ function plot!(::WinstonPackage, plt::Plot; kw...) e = Dict() - e[:color] = d[:color] + e[:color] = getColor(d[:color]) e[:linewidth] = d[:linewidth] e[:kind] = winston_linestyle[d[:linestyle]] e[:symbolkind] = winston_marker[d[:markershape]] # markercolor # same choices as `color`, or :match will set the color to be the same as `color` e[:symbolsize] = d[:markersize] / 5 - # fillto # fillto value for area plots # pos # (Int,Int), move the enclosing window to this position # screen # Integer, move enclosing window to this screen number (for multiscreen desktops) @@ -147,7 +147,7 @@ function plot!(::WinstonPackage, plt::Plot; kw...) ## lintype :path, :step, :stepinverted, :sticks, :dots, :none, :heatmap, :hexbin, :hist, :bar if d[:linetype] == :none - Winston.add(wplt, Winston.Points(d[:x], d[:y]; copy_remove(e, :kind)...)) + Winston.add(wplt, Winston.Points(d[:x], d[:y]; copy_remove(e, :kind)..., color=getColor(d[:markercolor]))) elseif d[:linetype] == :path x, y = d[:x], d[:y] @@ -160,7 +160,7 @@ function plot!(::WinstonPackage, plt::Plot; kw...) else y2 = Float64[fillrange for yi in y] end - Winston.add(wplt, Winston.FillBetween(x, y, x, y2, fillcolor=d[:color])) + Winston.add(wplt, Winston.FillBetween(x, y, x, y2, fillcolor=getColor(d[:fillcolor]))) end elseif d[:linetype] == :scatter @@ -201,7 +201,7 @@ function plot!(::WinstonPackage, plt::Plot; kw...) # markershape if d[:markershape] != :none - Winston.add(wplt, Winston.Points(d[:x], d[:y]; copy_remove(e, :kind)...)) + Winston.add(wplt, Winston.Points(d[:x], d[:y]; copy_remove(e, :kind)..., color=getColor(d[:markercolor]))) end