Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PlotsBase/src/Commons/attrs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ const _plot_defaults = KW(
:thickness_scaling => 1,
:display_type => :auto,
:warn_on_unsupported => true,
:safe_saving => true,
:extra_plot_kwargs => Dict(),
:extra_kwargs => :series, # directs collection of extra_kwargs
)
Expand Down
1 change: 1 addition & 0 deletions PlotsBase/src/arg_desc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const _arg_desc = KW(
Example: `pgfplotsx(); scatter(1:5, extra_kwargs=Dict(:subplot=>Dict("axis line shift" => "10pt"))`."""),
:fontfamily => (Union{AStr,Symbol}, "Default font family for title, legend entries, tick labels and guides."),
:warn_on_unsupported => (Bool, "Warn on unsupported attributes, series types and marker shapes."),
:safe_saving => (Bool, "Do not override existing files when saving to disk. Choose from (true, false), i.e. `plot(rand(10), safe_saving=false)` for enable file overriding"),

# subplot args
:title => (AStr, "Subplot title."),
Expand Down
5 changes: 4 additions & 1 deletion PlotsBase/src/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ file types, some also support svg, ps, eps, html and tex.
"""
function savefig(plt::Plot, fn) # fn might be an `AbstractString` or an `AbstractPath` from `FilePaths.jl`
fn = abspath(expanduser(fn))

if isfile(fn) && plt[:safe_saving]
@warn "Filename $fn already exists, defaulting to prevent overriding. To disable this behavior, provide `:safe_saving=false` kwarg, i.e. `plot(rand(10), safe_saving=false)`"
return
end
# get the extension
_, ext = splitext(fn)
ext = chop(ext, head = 1, tail = 0)
Expand Down