working on colors, args, and axis flip
This commit is contained in:
parent
e5007b6c87
commit
d6253c72d4
@ -30,7 +30,7 @@ const examples = PlotExample[
|
||||
[:(plot([sin,cos], 0, 4π))]),
|
||||
PlotExample("",
|
||||
"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, fillto=0))]),
|
||||
[:(plot(sin, x->sin(2x), 0, 2π, legend=false, fill=0))]),
|
||||
PlotExample("Global",
|
||||
"Change the guides/background/limits/ticks. You can also use shorthand functions: `title!`, `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))]),
|
||||
@ -42,7 +42,7 @@ const examples = PlotExample[
|
||||
[:(plot(Vector[rand(10), rand(20)]; marker=:ellipse, markersize=8, c=[:red,:blue]))]),
|
||||
PlotExample("Build plot in pieces",
|
||||
"Start with a base plot...",
|
||||
[:(plot(rand(100)/3, reg=true, fillto=0))]),
|
||||
[:(plot(rand(100)/3, reg=true, fill=0))]),
|
||||
PlotExample("",
|
||||
"and add to it later.",
|
||||
[:(scatter!(rand(100), markersize=6, c=:blue))]),
|
||||
@ -204,7 +204,7 @@ end
|
||||
# markersize # size of the marker
|
||||
# nbins # number of bins for heatmap/hexbin and histograms
|
||||
# heatmap_c # color cutoffs for Qwt heatmaps
|
||||
# fillto # fillto value for area plots
|
||||
# fill # fill value for area plots
|
||||
# title # string or symbol, title of the plot
|
||||
# xlabel # string or symbol, label on the bottom (x) axis
|
||||
# ylabel # string or symbol, label on the left (y) axis
|
||||
|
||||
File diff suppressed because one or more lines are too long
13
src/Plots.jl
13
src/Plots.jl
@ -44,6 +44,10 @@ export
|
||||
xticks!,
|
||||
yticks!,
|
||||
annotate!,
|
||||
xflip!,
|
||||
yflip!,
|
||||
xaxis!,
|
||||
yaxis!,
|
||||
|
||||
savefig,
|
||||
png,
|
||||
@ -116,6 +120,10 @@ yticks!{T<:Real}(v::AVec{T}) = plot!(yticks = v)
|
||||
xticks!{T<:Real,S<:AbstractString}(ticks::AVec{T}, labels::AVec{S}) = plot!(xticks = (ticks,labels))
|
||||
yticks!{T<:Real,S<:AbstractString}(ticks::AVec{T}, labels::AVec{S}) = plot!(yticks = (ticks,labels))
|
||||
annotate!(anns) = plot!(annotation = anns)
|
||||
xflip!(flip::Bool = true) = plot!(xflip = flip)
|
||||
yflip!(flip::Bool = true) = plot!(yflip = flip)
|
||||
xaxis!(args...) = plot!(xaxis = args)
|
||||
yaxis!(args...) = plot!(yaxis = args)
|
||||
|
||||
title!(plt::Plot, s::AbstractString) = plot!(plt; title = s)
|
||||
xlabel!(plt::Plot, s::AbstractString) = plot!(plt; xlabel = s)
|
||||
@ -129,6 +137,11 @@ yticks!{T<:Real}(plt::Plot, ticks::AVec{T}) = plot!(plt; yticks = tick
|
||||
xticks!{T<:Real,S<:AbstractString}(plt::Plot, ticks::AVec{T}, labels::AVec{S}) = plot!(plt; xticks = (ticks,labels))
|
||||
yticks!{T<:Real,S<:AbstractString}(plt::Plot, ticks::AVec{T}, labels::AVec{S}) = plot!(plt; yticks = (ticks,labels))
|
||||
annotate!(plt::Plot, anns) = plot!(plt; annotation = anns)
|
||||
xflip!(plt::Plot, flip::Bool = true) = plot!(plt; xflip = flip)
|
||||
yflip!(plt::Plot, flip::Bool = true) = plot!(plt; yflip = flip)
|
||||
xaxis!(plt::Plot, args...) = plot!(plt; xaxis = args)
|
||||
yaxis!(plt::Plot, args...) = plot!(plt; yaxis = args)
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
|
||||
@ -327,8 +327,9 @@ function addGadflyTicksGuide(gplt, ticks, isx::Bool)
|
||||
end
|
||||
end
|
||||
|
||||
# isContinuousScale(scale, isx::Bool) = isa(scale, Gadfly.Scale.ContinuousScale) && scale.vars[1] == (isx ? :x : :y)
|
||||
filterGadflyScale(gplt, isx::Bool) = filter!(scale -> scale.vars[1] != (isx ? :x : :y), gplt.scales)
|
||||
continuousAndSameAxis(scale, isx::Bool) = isa(scale, Gadfly.Scale.ContinuousScale) && scale.vars[1] == (isx ? :x : :y)
|
||||
# filterGadflyScale(gplt, isx::Bool) = filter!(scale -> scale.vars[1] != (isx ? :x : :y), gplt.scales)
|
||||
filterGadflyScale(gplt, isx::Bool) = filter!(scale -> !continuousAndSameAxis(scale, isx), gplt.scales)
|
||||
|
||||
|
||||
function getGadflyScaleFunction(d::Dict, isx::Bool)
|
||||
|
||||
16
src/utils.jl
16
src/utils.jl
@ -26,19 +26,19 @@ function histogramHack(; kw...)
|
||||
d[:x] = midpoints
|
||||
d[:y] = float(counts)
|
||||
d[:linetype] = :bar
|
||||
d[:fill] = d[:fill] == nothing ? 0.0 : d[:fill]
|
||||
d[:fillrange] = d[:fillrange] == nothing ? 0.0 : d[:fillrange]
|
||||
d
|
||||
end
|
||||
|
||||
doc"""
|
||||
A hacky replacement for a bar graph when the backend doesn't support bars directly.
|
||||
Convert it into a line chart with fillto set.
|
||||
Convert it into a line chart with fillrange set.
|
||||
"""
|
||||
function barHack(; kw...)
|
||||
d = Dict(kw)
|
||||
midpoints = d[:x]
|
||||
heights = d[:y]
|
||||
fillto = d[:fill] == nothing ? 0.0 : d[:fill]
|
||||
fillrange = d[:fillrange] == nothing ? 0.0 : d[:fillrange]
|
||||
|
||||
# estimate the edges
|
||||
dists = diff(midpoints) * 0.5
|
||||
@ -59,13 +59,13 @@ function barHack(; kw...)
|
||||
for i in 1:length(heights)
|
||||
e1, e2 = edges[i:i+1]
|
||||
append!(x, [e1, e1, e2, e2])
|
||||
append!(y, [fillto, heights[i], heights[i], fillto])
|
||||
append!(y, [fillrange, heights[i], heights[i], fillrange])
|
||||
end
|
||||
|
||||
d[:x] = x
|
||||
d[:y] = y
|
||||
d[:linetype] = :path
|
||||
d[:fill] = fillto
|
||||
d[:fillrange] = fillrange
|
||||
d
|
||||
end
|
||||
|
||||
@ -81,14 +81,14 @@ function sticksHack(; kw...)
|
||||
# these are the line vertices
|
||||
x = Float64[]
|
||||
y = Float64[]
|
||||
fillto = dLine[:fill] == nothing ? 0.0 : dLine[:fill]
|
||||
fillrange = dLine[:fillrange] == nothing ? 0.0 : dLine[:fillrange]
|
||||
|
||||
# calculate the vertices
|
||||
yScatter = dScatter[:y]
|
||||
for (i,xi) in enumerate(dScatter[:x])
|
||||
yi = yScatter[i]
|
||||
for j in 1:3 push!(x, xi) end
|
||||
append!(y, [fillto, yScatter[i], fillto])
|
||||
append!(y, [fillrange, yScatter[i], fillrange])
|
||||
end
|
||||
|
||||
# change the line args
|
||||
@ -96,7 +96,7 @@ function sticksHack(; kw...)
|
||||
dLine[:y] = y
|
||||
dLine[:linetype] = :path
|
||||
dLine[:markershape] = :none
|
||||
dLine[:fill] = nothing
|
||||
dLine[:fillrange] = nothing
|
||||
|
||||
# change the scatter args
|
||||
dScatter[:linetype] = :none
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user