bringing pyplot up to speed
This commit is contained in:
parent
2de017086d
commit
1c70346a61
@ -23,17 +23,14 @@ const examples = PlotExample[
|
|||||||
"A simple line plot of the columns.",
|
"A simple line plot of the columns.",
|
||||||
[:(plot(cumsum(randn(50,10),1), w=3))]),
|
[:(plot(cumsum(randn(50,10),1), w=3))]),
|
||||||
PlotExample("Functions",
|
PlotExample("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}.",
|
||||||
[:(plot(0:0.01:4π, [sin,cos]))]),
|
[:(plot(0:0.01:4π, [sin,cos]))]),
|
||||||
PlotExample("",
|
|
||||||
"You can also call it with plot(f, xmin, xmax).",
|
|
||||||
[:(plot([sin,cos], 0, 4π))]),
|
|
||||||
PlotExample("",
|
PlotExample("",
|
||||||
"Or make a parametric plot (i.e. plot: (fx(u), fy(u))) with plot(fx, fy, umin, umax).",
|
"Or make a parametric plot (i.e. plot: (fx(u), fy(u))) with plot(fx, fy, umin, umax).",
|
||||||
[:(plot(sin, x->sin(2x), 0, 2π, legend=false, fill=0))]),
|
[:(plot(sin, x->sin(2x), 0, 2π, leg=false, fill=(0,:orange)))]),
|
||||||
PlotExample("Global",
|
PlotExample("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!`",
|
||||||
[:(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))]),
|
||||||
PlotExample("Two-axis",
|
PlotExample("Two-axis",
|
||||||
"Use the `axis` arguments.\n\nNote: Currently only supported with Qwt and PyPlot",
|
"Use the `axis` arguments.\n\nNote: Currently only supported with Qwt and PyPlot",
|
||||||
[:(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"))]),
|
||||||
@ -42,10 +39,10 @@ const examples = PlotExample[
|
|||||||
[:(plot(Vector[rand(10), rand(20)]; marker=:ellipse, markersize=8, c=(:red, :blue)))]),
|
[:(plot(Vector[rand(10), rand(20)]; marker=:ellipse, markersize=8, c=(:red, :blue)))]),
|
||||||
PlotExample("Build plot in pieces",
|
PlotExample("Build plot in pieces",
|
||||||
"Start with a base plot...",
|
"Start with a base plot...",
|
||||||
[:(plot(rand(100)/3, reg=true, fill=0))]),
|
[:(plot(rand(100)/3, reg=true, fill=(0,:green)))]),
|
||||||
PlotExample("",
|
PlotExample("",
|
||||||
"and add to it later.",
|
"and add to it later.",
|
||||||
[:(scatter!(rand(100), markersize=6, c=:blue))]),
|
[:(scatter!(rand(100), markersize=6, c=:orange))]),
|
||||||
PlotExample("Heatmaps",
|
PlotExample("Heatmaps",
|
||||||
"",
|
"",
|
||||||
[:(heatmap(randn(10000),randn(10000), nbins=100))]),
|
[:(heatmap(randn(10000),randn(10000), nbins=100))]),
|
||||||
|
|||||||
@ -15,7 +15,8 @@ supportedArgs(::PyPlotPackage) = [
|
|||||||
:axis,
|
:axis,
|
||||||
:background_color,
|
:background_color,
|
||||||
:color,
|
:color,
|
||||||
# :fill,
|
:fillrange,
|
||||||
|
:fillcolor,
|
||||||
:foreground_color,
|
:foreground_color,
|
||||||
:group,
|
:group,
|
||||||
# :heatmap_c,
|
# :heatmap_c,
|
||||||
@ -64,6 +65,7 @@ subplotSupported(::PyPlotPackage) = false
|
|||||||
|
|
||||||
# convert colorant to 4-tuple RGBA
|
# convert colorant to 4-tuple RGBA
|
||||||
getPyPlotColor(c::Colorant) = map(f->float(f(c)), (red, green, blue, alpha))
|
getPyPlotColor(c::Colorant) = map(f->float(f(c)), (red, green, blue, alpha))
|
||||||
|
getPyPlotColor(scheme::ColorScheme) = getPyPlotColor(getColor(scheme))
|
||||||
|
|
||||||
# get the style (solid, dashed, etc)
|
# get the style (solid, dashed, etc)
|
||||||
function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol)
|
function getPyPlotLineStyle(linetype::Symbol, linestyle::Symbol)
|
||||||
@ -277,7 +279,18 @@ function plot!(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# this sets the bg color inside the grid
|
# this sets the bg color inside the grid
|
||||||
fig.o[:axes][1][:set_axis_bgcolor](getPyPlotColor(plt.initargs[:background_color]))
|
ax = getLeftAxis(fig)
|
||||||
|
ax[:set_axis_bgcolor](getPyPlotColor(plt.initargs[:background_color]))
|
||||||
|
|
||||||
|
fillrange = d[:fillrange]
|
||||||
|
if fillrange != nothing
|
||||||
|
fillcolor = getPyPlotColor(d[:fillcolor])
|
||||||
|
if typeof(fillrange) <: Union{Real, AVec}
|
||||||
|
ax[:fill_between](d[:x], fillrange, d[:y], facecolor = fillcolor)
|
||||||
|
else
|
||||||
|
ax[:fill_between](d[:x], fillrange..., facecolor = fillcolor)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
push!(plt.seriesargs, d)
|
push!(plt.seriesargs, d)
|
||||||
plt
|
plt
|
||||||
@ -323,16 +336,23 @@ function updatePlotItems(plt::Plot{PyPlotPackage}, d::Dict)
|
|||||||
ax[:set_ylabel](d[:yrightlabel])
|
ax[:set_ylabel](d[:yrightlabel])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# scales
|
||||||
|
ax = getLeftAxis(fig)
|
||||||
|
haskey(d, :xscale) && applyPyPlotScale(ax, d[:xscale], true)
|
||||||
|
haskey(d, :yscale) && applyPyPlotScale(ax, d[:yscale], false)
|
||||||
|
|
||||||
# limits and ticks
|
# limits and ticks
|
||||||
haskey(d, :xlims) && addPyPlotLims(d[:xlims], true)
|
haskey(d, :xlims) && addPyPlotLims(d[:xlims], true)
|
||||||
haskey(d, :ylims) && addPyPlotLims(d[:ylims], false)
|
haskey(d, :ylims) && addPyPlotLims(d[:ylims], false)
|
||||||
haskey(d, :xticks) && addPyPlotTicks(d[:xticks], true)
|
haskey(d, :xticks) && addPyPlotTicks(d[:xticks], true)
|
||||||
haskey(d, :yticks) && addPyPlotTicks(d[:yticks], false)
|
haskey(d, :yticks) && addPyPlotTicks(d[:yticks], false)
|
||||||
|
|
||||||
# scales
|
if get(d, :xflip, false)
|
||||||
ax = getLeftAxis(fig)
|
ax[:invert_xaxis]()
|
||||||
haskey(d, :xscale) && applyPyPlotScale(ax, d[:xscale], true)
|
end
|
||||||
haskey(d, :yscale) && applyPyPlotScale(ax, d[:yscale], false)
|
if get(d, :yflip, false)
|
||||||
|
ax[:invert_yaxis]()
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -71,12 +71,12 @@ const _masterColorList = [
|
|||||||
|
|
||||||
function darken(c, v=0.1)
|
function darken(c, v=0.1)
|
||||||
rgb = RGB(c)
|
rgb = RGB(c)
|
||||||
r = max(0, rgb.r - v)
|
r = max(0, min(rgb.r - v, 1))
|
||||||
g = max(0, rgb.g - v)
|
g = max(0, min(rgb.g - v, 1))
|
||||||
b = max(0, rgb.b - v)
|
b = max(0, min(rgb.b - v, 1))
|
||||||
RGB(r,g,b)
|
RGB(r,g,b)
|
||||||
end
|
end
|
||||||
function lighten(c, v=0.1)
|
function lighten(c, v=0.3)
|
||||||
darken(c, -v)
|
darken(c, -v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -47,6 +47,11 @@ convertSeriesIndex(subplt::Subplot, n::Int) = ceil(Int, n / subplt.p)
|
|||||||
|
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
function validateSubplotSupported()
|
||||||
|
if !subplotSupported()
|
||||||
|
error(CURRENT_BACKEND.sym, " does not support the subplot/subplot! commands at this time. Try one of: ", join(filter(pkg->subplotSupported(backendInstance(pkg)), backends()),", "))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
doc"""
|
doc"""
|
||||||
Create a series of plots:
|
Create a series of plots:
|
||||||
@ -59,6 +64,7 @@ Create a series of plots:
|
|||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
function subplot(args...; kw...)
|
function subplot(args...; kw...)
|
||||||
|
validateSubplotSupported()
|
||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
preprocessArgs!(d)
|
preprocessArgs!(d)
|
||||||
|
|
||||||
@ -102,6 +108,7 @@ Adds to a subplot.
|
|||||||
|
|
||||||
# current subplot
|
# current subplot
|
||||||
function subplot!(args...; kw...)
|
function subplot!(args...; kw...)
|
||||||
|
validateSubplotSupported()
|
||||||
subplot!(current(), args...; kw...)
|
subplot!(current(), args...; kw...)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -114,9 +121,10 @@ end
|
|||||||
|
|
||||||
# # this adds to a specific subplot... most plot commands will flow through here
|
# # this adds to a specific subplot... most plot commands will flow through here
|
||||||
function subplot!(subplt::Subplot, args...; kw...)
|
function subplot!(subplt::Subplot, args...; kw...)
|
||||||
if !subplotSupported()
|
validateSubplotSupported()
|
||||||
error(CURRENT_BACKEND.sym, " does not support the subplot/subplot! commands at this time. Try one of: ", join(filter(pkg->subplotSupported(backendInstance(pkg)), backends()),", "))
|
# if !subplotSupported()
|
||||||
end
|
# error(CURRENT_BACKEND.sym, " does not support the subplot/subplot! commands at this time. Try one of: ", join(filter(pkg->subplotSupported(backendInstance(pkg)), backends()),", "))
|
||||||
|
# end
|
||||||
|
|
||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
preprocessArgs!(d)
|
preprocessArgs!(d)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user