Skip to content
Merged
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
28 changes: 15 additions & 13 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ using Documenter
using PlotlyJS
using PlotlyBase

PlotlyJS.set_default_renderer(PlotlyJS.DOCS)

const THIS_DIR = dirname(@__FILE__)

# used in examples
using Distributions, HTTP, DataFrames, RDatasets, Colors, CSV, JSON
using Random, Dates, LinearAlgebra, DelimitedFiles

# to override display_dict below
import Documenter.Utilities: display_dict, limitstringmime
using Base64:stringmime

function display_dict(p::PlotlyBase.Plot)
out = Dict{MIME,Any}()
# Always generate text/plain
out[MIME"text/plain"()] = limitstringmime(MIME"text/plain"(), p)
svg_m = MIME"image/svg+xml"()
out[svg_m] = stringmime(svg_m, p)
out
end
# import Documenter.Utilities: display_dict, limitstringmime
# using Base64:stringmime

# function display_dict(p::PlotlyBase.Plot)
# out = Dict{MIME,Any}()
# # Always generate text/plain
# out[MIME"text/plain"()] = limitstringmime(MIME"text/plain"(), p)
# svg_m = MIME"image/svg+xml"()
# out[svg_m] = stringmime(svg_m, p)
# out
# end

display_dict(p::PlotlyJS.SyncPlot) = display_dict(p.plot)
# display_dict(p::PlotlyJS.SyncPlot) = display_dict(p.plot)

## handle examples
# Walk through each example in a file and get the markdown from `single_example`
Expand Down Expand Up @@ -101,7 +103,7 @@ makedocs(
sitename="PlotlyJS",
format=Documenter.HTML(
assets=[
asset("https://cdn.plot.ly/plotly-1.54.7.js")
"include_plotlyjs.js"
]
),
modules=[PlotlyJS, PlotlyBase],
Expand Down
12 changes: 12 additions & 0 deletions docs/src/assets/include_plotlyjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if (typeof require !== "undefined") {
console.log("Trying to load plotly.js via requirejs");
require.undef("plotly");
requirejs.config({
paths: {
plotly: ["https://cdn.plot.ly/plotly-2.3.0.min"],
},
});
require(["plotly"], function (Plotly) {
window._Plotly = Plotly;
});
}
112 changes: 105 additions & 7 deletions docs/src/examples/subplots.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ subplots1()
function subplots2()
p1 = linescatter1()
p2 = linescatter2()
p = [p1, p2]
p = [p1; p2]
p
end
subplots2()
Expand All @@ -42,29 +42,127 @@ subplots3()

```@example subplots
function subplots_withcomprehension()
hcat([plot(scatter(x = 1:5, y = rand(5))) for i in 1:3]...)
hcat([plot(scatter(x=1:5, y=rand(5))) for i in 1:3]...)
end
subplots_withcomprehension()
```

```@example subplots
function subplots_withsharedaxes()
data = [
scatter(x=1:3, y=2:4),
scatter(x=20:10:40, y=fill(5, 3), xaxis="x2", yaxis="y"),
scatter(x=2:4, y=600:100:800, xaxis="x", yaxis="y3"),
scatter(x=4000:1000:6000, y=7000:1000:9000, xaxis="x4", yaxis="y4")
scatter(x=1:3, y=2:4),
scatter(x=20:10:40, y=fill(5, 3), xaxis="x2", yaxis="y"),
scatter(x=2:4, y=600:100:800, xaxis="x", yaxis="y3"),
scatter(x=4000:1000:6000, y=7000:1000:9000, xaxis="x4", yaxis="y4")
]
layout = Layout(
xaxis_domain=[0, 0.45],
yaxis_domain=[0, 0.45],
xaxis4=attr(domain=[0.55, 1.0], anchor="y4"),
xaxis2_domain=[0.55, 1],
yaxis3_domain=[0.55, 1],
yaxis4=attr(domain=[0.55, 1], anchor="x4")
yaxis4=attr(domain=[0.55, 1], anchor="x4")
)
plot(data, layout)
end
subplots_withsharedaxes()
```

```@example subplots
function with_make_subplots1()

# The `shared_xaxes` argument to `make_subplots` can be used to link the x
# axes of subplots in the resulting figure. The `vertical_spacing` argument
# is used to control the vertical spacing between rows in the subplot grid.

# Here is an example that creates a figure with 3 vertically stacked
# subplots with linked x axes. A small vertical spacing value is used to
# reduce the spacing between subplot rows.

p = make_subplots(rows=3, cols=1, shared_xaxes=true, vertical_spacing=0.02)
add_trace!(p, scatter(x=0:2, y=10:12), row=3, col=1)
add_trace!(p, scatter(x=2:4, y=100:10:120), row=2, col=1)
add_trace!(p, scatter(x=3:5, y=1000:100:1200), row=1, col=1)
relayout!(p, title_text="Stacked Subplots with Shared X-Axes")
p
end
with_make_subplots1()
```

```@example subplots
function with_make_subplots2()
# The `shared_yaxes` argument to `make_subplots` can be used to link the y
# axes of subplots in the resulting figure.

# Here is an example that creates a figure with a 2 x 2 subplot grid, where
# the y axes of each row are linked.

p = make_subplots(rows=3, cols=2, shared_yaxes=true)
add_trace!(p, scatter(x=0:2, y=10:12), row=1, col=1)
add_trace!(p, scatter(x=20:10:40, y=1:3), row=1, col=2)
add_trace!(p, scatter(x=3:5, y=600:100:800), row=2, col=1)
add_trace!(p, scatter(x=3:5, y=1000:100:1200), row=2, col=2)
relayout!(p, title_text="Multiple Subplots with Shared Y-Axes")
p
end
with_make_subplots2()
```

```@example subplots
function with_make_subplots3()
# The `specs` argument to `make_subplots` is used to configure per-subplot
# options. `specs` must be a `Matrix` with dimensions that match those
# provided as the `rows` and `cols` arguments. The elements of `specs` may
# either be `missing`, indicating no subplot should be initialized starting
# with this grid cell, or an instance of `Spec` containing subplot options.
# The `colspan` subplot option specifies the number of grid columns that the
# subplot starting in the given cell should occupy. If unspecified,
# `colspan` defaults to 1.

# Here is an example that creates a 2 by 2 subplot grid containing 3
# subplots. The subplot `specs` element for position (2, 1) has a `colspan`
# value of 2, causing it to span the full figure width. The subplot `specs`
# element f or position (2, 2) is `None` because no subplot begins at this
# location in the grid.
p = make_subplots(
rows=2, cols=2,
specs=[Spec() Spec(); Spec(colspan=2) missing],
subplot_titles=["First Subplot" "Second Subplot"; "Third Subplot" missing]
)

add_trace!(p, scatter(x=[1, 2], y=[1, 2]), row=1, col=1)
add_trace!(p, scatter(x=[1, 2], y=[1, 2]), row=1, col=2)
add_trace!(p, scatter(x=[1, 2, 3], y=[2, 1, 2]), row=2, col=1)

relayout!(p, showlegend=false, title_text="Specs with Subplot Title")
p
end
with_make_subplots3()
```

```@example subplots
function with_make_subplots4()
# Here is an example that uses the `rowspan` and `colspan` subplot options
# to create a custom subplot layout with subplots of mixed sizes.
p = make_subplots(
rows=5, cols=2,
specs=[Spec() Spec(rowspan=2)
Spec() missing
Spec(rowspan=2, colspan=2) missing
missing missing
Spec() Spec()]
)

add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(1,1)"), row=1, col=1)
add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(1,2)"), row=1, col=2)
add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(2,1)"), row=2, col=1)
add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(3,1)"), row=3, col=1)
add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(5,1)"), row=5, col=1)
add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(5,2)"), row=5, col=2)

relayout!(p, height=600, width=600, title_text="specs examples")
p
end
with_make_subplots4()
```

4 changes: 2 additions & 2 deletions docs/src/examples/violin.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ violin_side_by_side()
```

```@example violin
function violin_styled()
function violin_style()
y1 = vcat(abs.(20 .* rand(100)), rand(UInt16, 300) .* 500 ./ typemax(UInt16))
y2 = [25.261999999999997, 66.5419, 98.2114, 0.09070629 ]
box = attr(fillcolor="black", line_color="black", width=0.01)
Expand Down Expand Up @@ -157,6 +157,6 @@ function violin_styled()
)
plot([trace1, trace2], layout)
end
violin_styled()
violin_style()
```

100 changes: 93 additions & 7 deletions examples/subplots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ end
function subplots2()
p1 = linescatter1()
p2 = linescatter2()
p = [p1, p2]
p = [p1; p2]
p
end

Expand All @@ -29,24 +29,110 @@ end


function subplots_withcomprehension()
hcat([plot(scatter(x = 1:5, y = rand(5))) for i in 1:3]...)
hcat([plot(scatter(x=1:5, y=rand(5))) for i in 1:3]...)
end


function subplots_withsharedaxes()
data = [
scatter(x=1:3, y=2:4),
scatter(x=20:10:40, y=fill(5, 3), xaxis="x2", yaxis="y"),
scatter(x=2:4, y=600:100:800, xaxis="x", yaxis="y3"),
scatter(x=4000:1000:6000, y=7000:1000:9000, xaxis="x4", yaxis="y4")
scatter(x=1:3, y=2:4),
scatter(x=20:10:40, y=fill(5, 3), xaxis="x2", yaxis="y"),
scatter(x=2:4, y=600:100:800, xaxis="x", yaxis="y3"),
scatter(x=4000:1000:6000, y=7000:1000:9000, xaxis="x4", yaxis="y4")
]
layout = Layout(
xaxis_domain=[0, 0.45],
yaxis_domain=[0, 0.45],
xaxis4=attr(domain=[0.55, 1.0], anchor="y4"),
xaxis2_domain=[0.55, 1],
yaxis3_domain=[0.55, 1],
yaxis4=attr(domain=[0.55, 1], anchor="x4")
yaxis4=attr(domain=[0.55, 1], anchor="x4")
)
plot(data, layout)
end

function with_make_subplots1()

# The `shared_xaxes` argument to `make_subplots` can be used to link the x
# axes of subplots in the resulting figure. The `vertical_spacing` argument
# is used to control the vertical spacing between rows in the subplot grid.

# Here is an example that creates a figure with 3 vertically stacked
# subplots with linked x axes. A small vertical spacing value is used to
# reduce the spacing between subplot rows.

p = make_subplots(rows=3, cols=1, shared_xaxes=true, vertical_spacing=0.02)
add_trace!(p, scatter(x=0:2, y=10:12), row=3, col=1)
add_trace!(p, scatter(x=2:4, y=100:10:120), row=2, col=1)
add_trace!(p, scatter(x=3:5, y=1000:100:1200), row=1, col=1)
relayout!(p, title_text="Stacked Subplots with Shared X-Axes")
p
end

function with_make_subplots2()
# The `shared_yaxes` argument to `make_subplots` can be used to link the y
# axes of subplots in the resulting figure.

# Here is an example that creates a figure with a 2 x 2 subplot grid, where
# the y axes of each row are linked.

p = make_subplots(rows=3, cols=2, shared_yaxes=true)
add_trace!(p, scatter(x=0:2, y=10:12), row=1, col=1)
add_trace!(p, scatter(x=20:10:40, y=1:3), row=1, col=2)
add_trace!(p, scatter(x=3:5, y=600:100:800), row=2, col=1)
add_trace!(p, scatter(x=3:5, y=1000:100:1200), row=2, col=2)
relayout!(p, title_text="Multiple Subplots with Shared Y-Axes")
p
end

function with_make_subplots3()
# The `specs` argument to `make_subplots` is used to configure per-subplot
# options. `specs` must be a `Matrix` with dimensions that match those
# provided as the `rows` and `cols` arguments. The elements of `specs` may
# either be `missing`, indicating no subplot should be initialized starting
# with this grid cell, or an instance of `Spec` containing subplot options.
# The `colspan` subplot option specifies the number of grid columns that the
# subplot starting in the given cell should occupy. If unspecified,
# `colspan` defaults to 1.

# Here is an example that creates a 2 by 2 subplot grid containing 3
# subplots. The subplot `specs` element for position (2, 1) has a `colspan`
# value of 2, causing it to span the full figure width. The subplot `specs`
# element f or position (2, 2) is `None` because no subplot begins at this
# location in the grid.
p = make_subplots(
rows=2, cols=2,
specs=[Spec() Spec(); Spec(colspan=2) missing],
subplot_titles=["First Subplot" "Second Subplot"; "Third Subplot" missing]
)

add_trace!(p, scatter(x=[1, 2], y=[1, 2]), row=1, col=1)
add_trace!(p, scatter(x=[1, 2], y=[1, 2]), row=1, col=2)
add_trace!(p, scatter(x=[1, 2, 3], y=[2, 1, 2]), row=2, col=1)

relayout!(p, showlegend=false, title_text="Specs with Subplot Title")
p
end

function with_make_subplots4()
# Here is an example that uses the `rowspan` and `colspan` subplot options
# to create a custom subplot layout with subplots of mixed sizes.
p = make_subplots(
rows=5, cols=2,
specs=[Spec() Spec(rowspan=2)
Spec() missing
Spec(rowspan=2, colspan=2) missing
missing missing
Spec() Spec()]
)

add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(1,1)"), row=1, col=1)
add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(1,2)"), row=1, col=2)
add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(2,1)"), row=2, col=1)
add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(3,1)"), row=3, col=1)
add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(5,1)"), row=5, col=1)
add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(5,2)"), row=5, col=2)

relayout!(p, height=600, width=600, title_text="specs examples")
p
end
2 changes: 1 addition & 1 deletion src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end
function Base.show(io::IO, mm::MIME"text/html", p::SyncPlot)
# if we are rendering docs -- short circuit and display html
if get_renderer() == DOCS
return show(io, mm, p.plot, full_html=false, include_plotlyjs="require")
return show(io, mm, p.plot, full_html=false, include_plotlyjs="require-loaded")
end
show(io, mm, p.scope)
end
Expand Down