diff --git a/docs/qwt_examples.md b/docs/qwt_examples.md index b48bf72e..f96805b6 100644 --- a/docs/qwt_examples.md +++ b/docs/qwt_examples.md @@ -1,11 +1,4 @@ -# Examples for backend: qwt - -- Supported arguments: `annotation`, `axis`, `background_color`, `color`, `color_palette`, `fillrange`, `fillcolor`, `foreground_color`, `group`, `heatmap_c`, `label`, `layout`, `legend`, `linestyle`, `linetype`, `linewidth`, `markershape`, `markercolor`, `markersize`, `n`, `nbins`, `nc`, `nr`, `pos`, `reg`, `show`, `size`, `title`, `windowtitle`, `x`, `xlabel`, `xlims`, `xticks`, `y`, `ylabel`, `ylims`, `yrightlabel`, `yticks`, `xscale`, `yscale` -- Supported values for axis: `:auto`, `:left`, `:right` -- Supported values for linetype: `:none`, `:line`, `:path`, `:steppre`, `:steppost`, `:sticks`, `:scatter`, `:heatmap`, `:hexbin`, `:hist`, `:bar`, `:hline`, `:vline` -- Supported values for linestyle: `:auto`, `:solid`, `:dash`, `:dot`, `:dashdot`, `:dashdotdot` -- Supported values for marker: `:none`, `:auto`, `:rect`, `:ellipse`, `:diamond`, `:utriangle`, `:dtriangle`, `:cross`, `:xcross`, `:star1`, `:star2`, `:hexagon` -- Is `subplot`/`subplot!` supported? Yes +## Examples for backend: qwt ### Initialize @@ -24,22 +17,31 @@ plot(fakedata(50,5),w=3) ![](../img/qwt/qwt_example_1.png) -### Functions +### Functions, adding data, and animations 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}. +Get series data: `x, y = plt[i]`. Set series data: `plt[i] = (x,y)`. Add to the series with `push!`/`append!`. + +Easily build animations. (`convert` or `ffmpeg` must be available to generate the animation.) Use command `gif(anim, filename, fps=15)` to save the animation. + ```julia -plot(0:0.01:4π,[sin,cos]) +p = plot([sin,cos],zeros(0),leg=false) +anim = Animation() +for x = linspace(0,10π,200) # /Users/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 43: + push!(p,x,Float64[sin(x),cos(x)]) # /Users/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 44: + frame(anim) +end ``` -![](../img/qwt/qwt_example_2.png) +![](../img/qwt/qwt_example_2.gif) -### +### Parametric plots -Or make a parametric plot (i.e. plot: (fx(u), fy(u))) with plot(fx, fy, umin, umax). +Plot function pair (x(u), y(u)). ```julia -plot(sin,(x->begin # /home/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 40: +plot(sin,(x->begin # /Users/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 50: sin(2x) end),0,2π,line=4,leg=false,fill=(0,:orange)) ``` @@ -63,7 +65,9 @@ scatter!(y,z=abs(y - 0.5),m=(10,:heat),lab="grad") 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(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) +plot(rand(20,3),xaxis=("XLABEL",(-5,30),0:2:20,:flip),background_color=RGB(0.2,0.2,0.2),leg=false) +title!("TITLE") +yaxis!("YLABEL",:log10) ``` ![](../img/qwt/qwt_example_5.png) @@ -75,7 +79,7 @@ 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/qwt/qwt_example_6.png) @@ -85,7 +89,7 @@ plot(Vector[randn(100),randn(100) * 100]; axis=[:l :r],ylabel="LEFT",yrightlabel 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,8),line=(:dot,3,[:black :orange])) +plot(Vector[rand(10),rand(20)],marker=(:ellipse,8),line=(:dot,3,[:black :orange])) ``` ![](../img/qwt/qwt_example_7.png) @@ -140,7 +144,7 @@ plot(x,y,line=(types,3),lab=map(string,types),ms=15) ```julia styles = setdiff(supportedStyles(),[:auto])' -plot(cumsum(randn(20,length(styles)),1); style=:auto,label=map(string,styles),w=5) +plot(cumsum(randn(20,length(styles)),1),style=:auto,label=map(string,styles),w=5) ``` ![](../img/qwt/qwt_example_12.png) @@ -150,8 +154,11 @@ 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=12) +markers = setdiff(supportedMarkers(),[:none,:auto,Shape])' +n = length(markers) +x = (linspace(0,10,n + 2))[2:end - 1] +y = repmat(reverse(x)',n,1) +scatter(x,y,m=(8,:auto),lab=map(string,markers),bg=:linen) ``` ![](../img/qwt/qwt_example_13.png) @@ -215,9 +222,17 @@ Currently only text annotations are supported. Pass in a tuple or vector-of-tup ```julia y = rand(10) -plot(y,ann=(3,y[3],"this is #3")) -annotate!([(5,y[5],"this is #5"),(9,y[10],"this is #10")]) +plot(y,ann=(3,y[3],text("this is #3",:left))) +annotate!([(5,y[5],text("this is #5",16,:red,:center)),(10,y[10],text("this is #10",:right,20,"courier"))]) ``` ![](../img/qwt/qwt_example_20.png) +- Supported arguments: `annotation`, `axis`, `background_color`, `color`, `color_palette`, `fillcolor`, `fillrange`, `foreground_color`, `group`, `label`, `layout`, `legend`, `linestyle`, `linetype`, `linewidth`, `markercolor`, `markershape`, `markersize`, `n`, `nbins`, `nc`, `nr`, `pos`, `show`, `size`, `smooth`, `title`, `windowtitle`, `x`, `xlabel`, `xlims`, `xscale`, `xticks`, `y`, `ylabel`, `ylims`, `yrightlabel`, `yscale`, `yticks` +- Supported values for axis: `:auto`, `:left`, `:right` +- Supported values for linetype: `:bar`, `:heatmap`, `:hexbin`, `:hist`, `:hline`, `:line`, `:none`, `:path`, `:scatter`, `:steppost`, `:steppre`, `:sticks`, `:vline` +- Supported values for linestyle: `:auto`, `:dash`, `:dashdot`, `:dashdotdot`, `:dot`, `:solid` +- Supported values for marker: `:auto`, `:cross`, `:diamond`, `:dtriangle`, `:ellipse`, `:hexagon`, `:none`, `:rect`, `:star5`, `:star8`, `:utriangle`, `:xcross` +- Is `subplot`/`subplot!` supported? Yes + +(Automatically generated: 2015-10-18T00:40:24) \ No newline at end of file diff --git a/img/qwt/qwt_example_1.png b/img/qwt/qwt_example_1.png index 923a8e97..e671d85c 100644 Binary files a/img/qwt/qwt_example_1.png and b/img/qwt/qwt_example_1.png differ diff --git a/img/qwt/qwt_example_10.png b/img/qwt/qwt_example_10.png index 966de20b..3cada0e5 100644 Binary files a/img/qwt/qwt_example_10.png and b/img/qwt/qwt_example_10.png differ diff --git a/img/qwt/qwt_example_11.png b/img/qwt/qwt_example_11.png index 151e76a0..f7cfc2d2 100644 Binary files a/img/qwt/qwt_example_11.png and b/img/qwt/qwt_example_11.png differ diff --git a/img/qwt/qwt_example_12.png b/img/qwt/qwt_example_12.png index 3f7f2c38..d84c3598 100644 Binary files a/img/qwt/qwt_example_12.png and b/img/qwt/qwt_example_12.png differ diff --git a/img/qwt/qwt_example_13.png b/img/qwt/qwt_example_13.png index 4cd25e66..9b582ced 100644 Binary files a/img/qwt/qwt_example_13.png and b/img/qwt/qwt_example_13.png differ diff --git a/img/qwt/qwt_example_14.png b/img/qwt/qwt_example_14.png index 3a22fbdd..f3fa8f73 100644 Binary files a/img/qwt/qwt_example_14.png and b/img/qwt/qwt_example_14.png differ diff --git a/img/qwt/qwt_example_15.png b/img/qwt/qwt_example_15.png index 749055f8..0c49a567 100644 Binary files a/img/qwt/qwt_example_15.png and b/img/qwt/qwt_example_15.png differ diff --git a/img/qwt/qwt_example_16.png b/img/qwt/qwt_example_16.png index 9bb8914d..afdbbd99 100644 Binary files a/img/qwt/qwt_example_16.png and b/img/qwt/qwt_example_16.png differ diff --git a/img/qwt/qwt_example_17.png b/img/qwt/qwt_example_17.png index 4d7db770..61951995 100644 Binary files a/img/qwt/qwt_example_17.png and b/img/qwt/qwt_example_17.png differ diff --git a/img/qwt/qwt_example_18.png b/img/qwt/qwt_example_18.png index 158c1edd..773c4e92 100644 Binary files a/img/qwt/qwt_example_18.png and b/img/qwt/qwt_example_18.png differ diff --git a/img/qwt/qwt_example_2.gif b/img/qwt/qwt_example_2.gif new file mode 100644 index 00000000..168fc42d Binary files /dev/null and b/img/qwt/qwt_example_2.gif differ diff --git a/img/qwt/qwt_example_20.png b/img/qwt/qwt_example_20.png index a4ea54d0..52c5fc55 100644 Binary files a/img/qwt/qwt_example_20.png and b/img/qwt/qwt_example_20.png differ diff --git a/img/qwt/qwt_example_3.png b/img/qwt/qwt_example_3.png index 77bc618d..c825d254 100644 Binary files a/img/qwt/qwt_example_3.png and b/img/qwt/qwt_example_3.png differ diff --git a/img/qwt/qwt_example_4.png b/img/qwt/qwt_example_4.png index fce8f2c8..05006146 100644 Binary files a/img/qwt/qwt_example_4.png and b/img/qwt/qwt_example_4.png differ diff --git a/img/qwt/qwt_example_5.png b/img/qwt/qwt_example_5.png index 8b450eb1..4a8bce9f 100644 Binary files a/img/qwt/qwt_example_5.png and b/img/qwt/qwt_example_5.png differ diff --git a/img/qwt/qwt_example_6.png b/img/qwt/qwt_example_6.png index 472cc9fe..cdbb3190 100644 Binary files a/img/qwt/qwt_example_6.png and b/img/qwt/qwt_example_6.png differ diff --git a/img/qwt/qwt_example_7.png b/img/qwt/qwt_example_7.png index be4a55e2..93f062d0 100644 Binary files a/img/qwt/qwt_example_7.png and b/img/qwt/qwt_example_7.png differ diff --git a/img/qwt/qwt_example_8.png b/img/qwt/qwt_example_8.png index 4e971b3c..447f0dbe 100644 Binary files a/img/qwt/qwt_example_8.png and b/img/qwt/qwt_example_8.png differ diff --git a/img/qwt/qwt_example_9.png b/img/qwt/qwt_example_9.png index 053f647d..3adb050f 100644 Binary files a/img/qwt/qwt_example_9.png and b/img/qwt/qwt_example_9.png differ diff --git a/src/backends/qwt.jl b/src/backends/qwt.jl index 2ec971d8..6d85a5d9 100644 --- a/src/backends/qwt.jl +++ b/src/backends/qwt.jl @@ -120,6 +120,9 @@ function adjustQwtKeywords(plt::Plot{QwtPackage}, iscreating::Bool; kw...) d[_qwtAliases[k]] = d[k] end end + + d[:x] = collect(d[:x]) + d[:y] = collect(d[:y]) d end @@ -212,6 +215,16 @@ function addLineMarker(plt::Plot{QwtPackage}, d::Dict) # marker[:attach](plt.o.widget) end +function createQwtAnnotation(plt::Plot, x, y, val::PlotText) + marker = Qwt.QWT.QwtPlotMarker() + marker[:setValue](x, y) + qwttext = Qwt.QWT.QwtText(val.str) + qwttext[:setFont](Qwt.QT.QFont(val.font.family, val.font.pointsize)) + qwttext[:setColor](Qwt.convertRGBToQColor(getColor(val.font.color))) + marker[:setLabel](qwttext) + marker[:attach](plt.o.widget) +end + function createQwtAnnotation(plt::Plot, x, y, val::@compat(AbstractString)) marker = Qwt.QWT.QwtPlotMarker() marker[:setValue](x, y) diff --git a/src/plot.jl b/src/plot.jl index 74edb2f3..ebc6508b 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -116,6 +116,11 @@ function plot!(plt::Plot, args...; kw...) setTicksFromStringVector(d, di, :x, :xticks) setTicksFromStringVector(d, di, :y, :yticks) + # remove plot args + for k in keys(_plotDefaults) + delete!(di, k) + end + dumpdict(di, "Series $i") plot!(plt.backend, plt; di...) @@ -281,9 +286,9 @@ function createKWargsList(plt::PlottingObject, x, y; kw...) # build the series arg dict numUncounted = get(d, :numUncounted, 0) n = plt.n + i + numUncounted - dumpdict(d, "before getSeriesArgs") + # dumpdict(d, "before getSeriesArgs") d = getSeriesArgs(plt.backend, getinitargs(plt, n), d, i + numUncounted, convertSeriesIndex(plt, n), n) - dumpdict(d, "after getSeriesArgs") + # dumpdict(d, "after getSeriesArgs") d[:x], d[:y] = computeXandY(xs[mod1(i,mx)], ys[mod1(i,my)]) if haskey(d, :idxfilter)