Merge pull request #2471 from daschw/staticarrays
fix StaticArray plotting
This commit is contained in:
commit
3fb45764b2
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ deps/plotly-latest.min.js
|
|||||||
deps/build.log
|
deps/build.log
|
||||||
deps/deps.jl
|
deps/deps.jl
|
||||||
Manifest.toml
|
Manifest.toml
|
||||||
|
dev/
|
||||||
|
|||||||
@ -57,13 +57,15 @@ ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
|
|||||||
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
|
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
|
||||||
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
|
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
|
||||||
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
|
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
|
||||||
|
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
|
||||||
PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925"
|
PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925"
|
||||||
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
|
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
|
||||||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
|
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
|
||||||
|
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
|
||||||
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
|
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
|
||||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||||
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
|
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
|
||||||
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"
|
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"
|
||||||
|
|
||||||
[targets]
|
[targets]
|
||||||
test = ["FileIO", "GeometryTypes", "Gtk", "ImageMagick", "Images", "LaTeXStrings", "LibGit2", "PGFPlotsX", "Random", "RDatasets", "StatsPlots", "Test", "UnicodePlots", "VisualRegressionTests"]
|
test = ["FileIO", "GeometryTypes", "Gtk", "ImageMagick", "Images", "LaTeXStrings", "LibGit2", "OffsetArrays", "PGFPlotsX", "Random", "RDatasets", "StaticArrays", "StatsPlots", "Test", "UnicodePlots", "VisualRegressionTests"]
|
||||||
|
|||||||
@ -875,6 +875,20 @@ const _examples = PlotExample[
|
|||||||
end,
|
end,
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
PlotExample(
|
||||||
|
"Array Types",
|
||||||
|
"Plots supports different `Array` types that follow the `AbstractArray` interface, like `StaticArrays` and `OffsetArrays.`",
|
||||||
|
[
|
||||||
|
quote
|
||||||
|
begin
|
||||||
|
using StaticArrays, OffsetArrays
|
||||||
|
sv = SVector{10}(rand(10))
|
||||||
|
ov = OffsetVector(rand(10), -2)
|
||||||
|
plot([sv, ov], label = ["StaticArray" "OffsetArray"])
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
],
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
# Some constants for PlotDocs and PlotReferenceImages
|
# Some constants for PlotDocs and PlotReferenceImages
|
||||||
|
|||||||
@ -15,9 +15,11 @@ prepareSeriesData(x) = error("Cannot convert $(typeof(x)) to series data for plo
|
|||||||
prepareSeriesData(::Nothing) = nothing
|
prepareSeriesData(::Nothing) = nothing
|
||||||
prepareSeriesData(t::Tuple{T, T}) where {T<:Number} = t
|
prepareSeriesData(t::Tuple{T, T}) where {T<:Number} = t
|
||||||
prepareSeriesData(f::Function) = f
|
prepareSeriesData(f::Function) = f
|
||||||
prepareSeriesData(a::AbstractArray{<:MaybeNumber}) = replace!(
|
prepareSeriesData(ar::AbstractRange{<:Number}) = ar
|
||||||
x -> ismissing(x) || isinf(x) ? NaN : x,
|
function prepareSeriesData(a::AbstractArray{<:MaybeNumber})
|
||||||
map(float,a))
|
f = isimmutable(a) ? replace : replace!
|
||||||
|
a = f(x -> ismissing(x) || isinf(x) ? NaN : x, map(float, a))
|
||||||
|
end
|
||||||
prepareSeriesData(a::AbstractArray{<:MaybeString}) = replace(x -> ismissing(x) ? "" : x, a)
|
prepareSeriesData(a::AbstractArray{<:MaybeString}) = replace(x -> ismissing(x) ? "" : x, a)
|
||||||
prepareSeriesData(s::Surface{<:AMat{<:MaybeNumber}}) = Surface(prepareSeriesData(s.surf))
|
prepareSeriesData(s::Surface{<:AMat{<:MaybeNumber}}) = Surface(prepareSeriesData(s.surf))
|
||||||
prepareSeriesData(s::Surface) = s # non-numeric Surface, such as an image
|
prepareSeriesData(s::Surface) = s # non-numeric Surface, such as an image
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user