don't error on savefig without an ext, use default; closes #32
This commit is contained in:
parent
69d574c587
commit
1f58ef5140
51
src/Plots.jl
51
src/Plots.jl
@ -125,12 +125,28 @@ annotate!(plt::Plot, anns) = plot!(plt; annotation =
|
|||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
defaultOutputFormat(plt::PlottingObject) = "png"
|
||||||
|
|
||||||
|
function png(plt::PlottingObject, fn::AbstractString)
|
||||||
|
fn = addExtension(fn, "png")
|
||||||
|
io = open(fn, "w")
|
||||||
|
writemime(io, MIME("image/png"), plt)
|
||||||
|
close(io)
|
||||||
|
end
|
||||||
|
png(fn::AbstractString) = png(current(), fn)
|
||||||
|
|
||||||
|
|
||||||
|
const _savemap = Dict(
|
||||||
|
"png" => png,
|
||||||
|
)
|
||||||
|
|
||||||
function getExtension(fn::AbstractString)
|
function getExtension(fn::AbstractString)
|
||||||
pieces = split(fn, ".")
|
pieces = split(fn, ".")
|
||||||
if length(pieces) < 2
|
length(pieces) > 1 || error("Can't extract file extension: ", fn)
|
||||||
error("Can't extract file extension: ", fn)
|
ext = pieces[end]
|
||||||
end
|
haskey(_savemap, ext) || error("Invalid file extension: ", fn)
|
||||||
pieces[end]
|
ext
|
||||||
end
|
end
|
||||||
|
|
||||||
function addExtension(fn::AbstractString, ext::AbstractString)
|
function addExtension(fn::AbstractString, ext::AbstractString)
|
||||||
@ -146,22 +162,19 @@ function addExtension(fn::AbstractString, ext::AbstractString)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function png(plt::PlottingObject, fn::AbstractString)
|
|
||||||
fn = addExtension(fn, "png")
|
|
||||||
io = open(fn, "w")
|
|
||||||
writemime(io, MIME("image/png"), plt)
|
|
||||||
close(io)
|
|
||||||
end
|
|
||||||
png(fn::AbstractString) = png(current(), fn)
|
|
||||||
|
|
||||||
|
|
||||||
const _savemap = Dict(
|
|
||||||
"png" => png,
|
|
||||||
)
|
|
||||||
|
|
||||||
function savefig(plt::PlottingObject, fn::AbstractString)
|
function savefig(plt::PlottingObject, fn::AbstractString)
|
||||||
ext = getExtension(fn)
|
|
||||||
|
# get the extension
|
||||||
|
local ext
|
||||||
|
try
|
||||||
|
ext = getExtension(fn)
|
||||||
|
catch
|
||||||
|
# if we couldn't extract the extension, add the default
|
||||||
|
ext = defaultOutputFormat(plt)
|
||||||
|
fn = addExtension(fn, ext)
|
||||||
|
end
|
||||||
|
|
||||||
|
# save it
|
||||||
func = get(_savemap, ext) do
|
func = get(_savemap, ext) do
|
||||||
error("Unsupported extension $ext with filename ", fn)
|
error("Unsupported extension $ext with filename ", fn)
|
||||||
end
|
end
|
||||||
|
|||||||
12
src/args.jl
12
src/args.jl
@ -351,6 +351,12 @@ function getPlotArgs(pkg::PlottingPackage, kw, idx::Int)
|
|||||||
d[k] = _plotDefaults[k]
|
d[k] = _plotDefaults[k]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for k in (:xscale, :yscale)
|
||||||
|
if haskey(_scaleAliases, d[k])
|
||||||
|
d[k] = _scaleAliases[d[k]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# convert color
|
# convert color
|
||||||
handlePlotColors(pkg, d)
|
handlePlotColors(pkg, d)
|
||||||
@ -386,12 +392,6 @@ function getSeriesArgs(pkg::PlottingPackage, initargs::Dict, kw, commandIndex::I
|
|||||||
d[:linetype] = _typeAliases[d[:linetype]]
|
d[:linetype] = _typeAliases[d[:linetype]]
|
||||||
end
|
end
|
||||||
|
|
||||||
for k in (:xscale, :yscale)
|
|
||||||
if haskey(_scaleAliases, d[k])
|
|
||||||
d[k] = _scaleAliases[d[k]]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
aliasesAndAutopick(d, :axis, _axesAliases, supportedAxes(pkg), plotIndex)
|
aliasesAndAutopick(d, :axis, _axesAliases, supportedAxes(pkg), plotIndex)
|
||||||
aliasesAndAutopick(d, :linestyle, _styleAliases, supportedStyles(pkg), plotIndex)
|
aliasesAndAutopick(d, :linestyle, _styleAliases, supportedStyles(pkg), plotIndex)
|
||||||
aliasesAndAutopick(d, :marker, _markerAliases, supportedMarkers(pkg), plotIndex)
|
aliasesAndAutopick(d, :marker, _markerAliases, supportedMarkers(pkg), plotIndex)
|
||||||
|
|||||||
@ -355,7 +355,7 @@ function addGadflyLimitsScale(gplt, d::Dict, isx::Bool)
|
|||||||
|
|
||||||
# get the correct scale function
|
# get the correct scale function
|
||||||
gfunc, hasScaleKey = getGadflyScaleFunction(d, isx)
|
gfunc, hasScaleKey = getGadflyScaleFunction(d, isx)
|
||||||
@show d gfunc hasScaleKey
|
# @show d gfunc hasScaleKey
|
||||||
|
|
||||||
# do we want to add min/max limits for the axis?
|
# do we want to add min/max limits for the axis?
|
||||||
limsym = isx ? :xlims : :ylims
|
limsym = isx ? :xlims : :ylims
|
||||||
@ -375,14 +375,14 @@ function addGadflyLimitsScale(gplt, d::Dict, isx::Bool)
|
|||||||
error("Invalid input for $(isx ? "xlims" : "ylims"): ", lims)
|
error("Invalid input for $(isx ? "xlims" : "ylims"): ", lims)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@show limargs
|
# @show limargs
|
||||||
|
|
||||||
# replace any current scales with this one
|
# replace any current scales with this one
|
||||||
if hasScaleKey || !isempty(limargs)
|
if hasScaleKey || !isempty(limargs)
|
||||||
filterGadflyScale(gplt, isx)
|
filterGadflyScale(gplt, isx)
|
||||||
push!(gplt.scales, gfunc(; limargs...))
|
push!(gplt.scales, gfunc(; limargs...))
|
||||||
end
|
end
|
||||||
@show gplt.scales
|
# @show gplt.scales
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -60,8 +60,14 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# this adds to the current plot
|
# this adds to the current plot, or creates a new plot if none are current
|
||||||
function plot!(args...; kw...)
|
function plot!(args...; kw...)
|
||||||
|
local plt
|
||||||
|
try
|
||||||
|
plt = current()
|
||||||
|
catch
|
||||||
|
return plot(args...; kw...)
|
||||||
|
end
|
||||||
plot!(current(), args...; kw...)
|
plot!(current(), args...; kw...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user