foreground_color fixes and added support in pyplot
This commit is contained in:
parent
454630dace
commit
be43e64743
18
src/args.jl
18
src/args.jl
@ -115,6 +115,7 @@ _plotDefaults[:ylabel] = ""
|
||||
_plotDefaults[:yrightlabel] = ""
|
||||
_plotDefaults[:legend] = true
|
||||
_plotDefaults[:background_color] = colorant"white"
|
||||
_plotDefaults[:foreground_color] = :auto
|
||||
_plotDefaults[:xticks] = true
|
||||
_plotDefaults[:yticks] = true
|
||||
_plotDefaults[:size] = (800,600)
|
||||
@ -125,7 +126,7 @@ _plotDefaults[:show] = false
|
||||
|
||||
# TODO: x/y scales
|
||||
|
||||
const _allArgs = sort(collect(intersect(keys(_seriesDefaults), keys(_plotDefaults))))
|
||||
const _allArgs = sort(collect(union(keys(_seriesDefaults), keys(_plotDefaults))))
|
||||
supportedArgs(::PlottingPackage) = _allArgs
|
||||
supportedArgs() = supportedArgs(plotter())
|
||||
|
||||
@ -246,6 +247,7 @@ function warnOnUnsupported(pkg::PlottingPackage, d::Dict)
|
||||
end
|
||||
|
||||
|
||||
# build the argument dictionary for the plot
|
||||
function getPlotArgs(pkg::PlottingPackage, kw, idx::Int)
|
||||
d = Dict(kw)
|
||||
|
||||
@ -274,8 +276,7 @@ end
|
||||
|
||||
|
||||
|
||||
|
||||
# note: idx is the index of this series within this call, n is the index of the series from all calls to plot/subplot
|
||||
# build the argument dictionary for a series
|
||||
function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::Int, plotIndex::Int, globalIndex::Int) # TODO, pass in initargs, not plt
|
||||
d = Dict(kw)
|
||||
|
||||
@ -300,17 +301,6 @@ function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::I
|
||||
aliasesAndAutopick(d, :linestyle, _styleAliases, supportedStyles(pkg), plotIndex)
|
||||
aliasesAndAutopick(d, :marker, _markerAliases, supportedMarkers(pkg), plotIndex)
|
||||
|
||||
# # auto-pick
|
||||
# if d[:axis] == :auto
|
||||
# d[:axis] = autopick_ignore_none_auto(supportedAxes(pkg), plotIndex)
|
||||
# end
|
||||
# if d[:linestyle] == :auto
|
||||
# d[:linestyle] = autopick_ignore_none_auto(supportedStyles(pkg), plotIndex)
|
||||
# end
|
||||
# if d[:marker] == :auto
|
||||
# d[:marker] = autopick_ignore_none_auto(supportedMarkers(pkg), plotIndex)
|
||||
# end
|
||||
|
||||
# update color
|
||||
d[:color] = getSeriesRGBColor(d[:color], initargs, plotIndex)
|
||||
|
||||
|
||||
@ -94,6 +94,20 @@ function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
|
||||
# return linetype == :hist ? PyPlot.plt[:hist] : (linetype in (:sticks,:bar) ? PyPlot.bar : (linetype in (:heatmap,:hexbin) ? PyPlot.hexbin : PyPlot.plot))
|
||||
end
|
||||
|
||||
function updateAxisColors(o, fgcolor)
|
||||
ax = o[:axes][1]
|
||||
for loc in ("bottom", "top", "left", "right")
|
||||
ax[:spines][loc][:set_color](fgcolor)
|
||||
end
|
||||
for axis in ("x", "y")
|
||||
ax[:tick_params](axis=axis, colors=fgcolor, which="both")
|
||||
end
|
||||
for axis in (:yaxis, :xaxis)
|
||||
ax[axis][:label][:set_color](fgcolor)
|
||||
end
|
||||
ax[:title][:set_color](fgcolor)
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
# TODO:
|
||||
@ -217,6 +231,7 @@ end
|
||||
|
||||
function Base.display(::PyPlotPackage, plt::Plot)
|
||||
addPyPlotLegend(plt)
|
||||
updateAxisColors(plt.o.o, getPyPlotColor(plt.initargs[:foreground_color]))
|
||||
display(plt.o)
|
||||
end
|
||||
|
||||
|
||||
@ -137,7 +137,14 @@ end
|
||||
# TODO: allow the setting of the algorithm, either by passing a symbol (:colordiff, :fixed, etc) or a function?
|
||||
|
||||
function getBackgroundRGBColor(c, d::Dict)
|
||||
bgcolor = convertColor(d[:background_color])
|
||||
if :background_color in supportedArgs()
|
||||
bgcolor = convertColor(d[:background_color])
|
||||
else
|
||||
bgcolor = _plotDefaults[:background_color]
|
||||
if d[:background_color] != _plotDefaults[:background_color]
|
||||
warn("Cannot set background_color with backend $(plotter())")
|
||||
end
|
||||
end
|
||||
d[:background_color] = bgcolor
|
||||
|
||||
# d[:color_palette] = getPaletteUsingDistinguishableColors(bgcolor)
|
||||
@ -148,6 +155,8 @@ function getBackgroundRGBColor(c, d::Dict)
|
||||
# on how dark the background is.
|
||||
if !haskey(d, :foreground_color) || d[:foreground_color] == :auto
|
||||
d[:foreground_color] = isdark(bgcolor) ? colorant"white" : colorant"black"
|
||||
else
|
||||
d[:foreground_color] = convertColor(d[:foreground_color])
|
||||
end
|
||||
|
||||
bgcolor
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user