Skip to content

Commit 340119e

Browse files
author
Alexey Stukalov
committed
update savefig docs
1 parent 9e951ee commit 340119e

File tree

1 file changed

+34
-48
lines changed

1 file changed

+34
-48
lines changed

docs/src/manipulating_plots.md

Lines changed: 34 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -138,70 +138,56 @@ More examples are being worked on at this time (2021-07-14), but for now you can
138138

139139
## Saving figures
140140

141-
142-
Figures can be saved in a variety of formats using the `savefig` function.
141+
Figures can be saved in a variety of formats using the [`savefig`](@ref) function.
143142

144143
!!! note
145-
Note that the docs below are shown for the `PlotlyBase.Plot` type, but are also defined for `PlotlyJS.SyncPlot`. Thus, you can use these methods after calling either `plot` or `Plot`.
146-
147-
This function has a few methods:
144+
Note that the docs below are shown for the `PlotlyBase.Plot` type, but are also defined for `PlotlyJS.SyncPlot`.
145+
Thus, you can use these methods after calling either `plot` or `Plot`.
148146

149-
**1**
147+
The `savefig` function can be called in a few ways:
150148

151-
```@docs
152-
savefig(::Union{PlotlyBase.Plot}, ::String)
153-
```
154-
155-
When using this method the format of the file is inferred based on the extension
156-
of the second argument. The examples below show the possible export formats:
157-
158-
```julia
159-
savefig(p::Union{Plot,SyncPlot}, "output_filename.pdf")
160-
savefig(p::Union{Plot,SyncPlot}, "output_filename.html")
161-
savefig(p::Union{Plot,SyncPlot}, "output_filename.json")
162-
savefig(p::Union{Plot,SyncPlot}, "output_filename.png")
163-
savefig(p::Union{Plot,SyncPlot}, "output_filename.svg")
164-
savefig(p::Union{Plot,SyncPlot}, "output_filename.jpeg")
165-
savefig(p::Union{Plot,SyncPlot}, "output_filename.webp")
166-
```
149+
**Save into a file**
167150

168-
**2**
151+
`savefig(p, filename)` saves the plot `p` into `filename`.
152+
Unless explicitly specified, the format of the file is inferred from the `filename` extension.
153+
The examples demonstrate the supported formats:
169154

170155
```julia
171-
savefig(
172-
io::IO,
173-
p::Plot;
174-
width::Union{Nothing,Int}=nothing,
175-
height::Union{Nothing,Int}=nothing,
176-
scale::Union{Nothing,Real}=nothing,
177-
format::String="png"
178-
)
156+
savefig(p, "output_filename.pdf")
157+
savefig(p, "output_filename.html")
158+
savefig(p, "output_filename.json")
159+
savefig(p, "output_filename.png")
160+
savefig(p, "output_filename.svg")
161+
savefig(p, "output_filename.jpeg")
162+
savefig(p, "output_filename.webp")
179163
```
180164

181-
This method allows you to save a plot directly to an open IO stream.
165+
**Save into a stream**
182166

183-
See the [`savefig(::IO, ::PlotlyBase.Plot)`](@ref) API docs for more information.
167+
`savefig(io, p)` saves the plot `p` into the open `io` stream.
168+
The figure format could be specified with the `format` keyword, the default format is *PNG*.
184169

185-
**3**
170+
**Display on the screen**
186171

172+
*PlotlyJS.jl* overloads the `Base.show` method to hook into Julia's rich display system:
187173
```julia
188-
Base.show(::IO, ::MIME, ::Union{PlotlyBase.Plot})
174+
Base.show(io::IO, ::MIME, p::Union{PlotlyBase.Plot})
189175
```
176+
Internally, this `Base.show` implementation calls `savefig(io, p)`,
177+
and the `MIME` argument allows to specify the output format.
178+
179+
The following MIME formats are supported:
180+
* `::MIME"application/pdf`
181+
* `::MIME"image/png`
182+
* `::MIME"image/svg+xml`
183+
* `::MIME"image/eps`
184+
* `::MIME"image/jpeg`
185+
* `::MIME"application/json"`
186+
* `::MIME"application/json; charset=UTF-8"`
190187

191-
This method hooks into Julia's rich display system.
192-
193-
Possible arguments for the second argument are shown in the examples below:
194-
195-
```julia
196-
savefig(io::IO, ::MIME"application/pdf", p::Union{Plot,SyncPlot})
197-
savefig(io::IO, ::MIME"image/png", p::Union{Plot,SyncPlot})
198-
savefig(io::IO, ::MIME"image/svg+xml", p::Union{Plot,SyncPlot})
199-
savefig(io::IO, ::MIME"image/eps", p::Union{Plot,SyncPlot})
200-
savefig(io::IO, ::MIME"image/jpeg", p::Union{Plot,SyncPlot})
201-
savefig(io::IO, ::MIME"application/json", p::Union{Plot,SyncPlot})
202-
savefig(io::IO, ::MIME"application/json; charset=UTF-8", p::Union{Plot,SyncPlot})
188+
```@docs
189+
savefig
203190
```
204-
205191
!!! note
206192
You can also save the json for a figure by calling
207193
`savejson(p::Union{Plot,SyncPlot}, filename::String)`.

0 commit comments

Comments
 (0)