Skip to content

plots with missing and NaN data #54

Description

@deszoeke

Missing and missing are first class types/values in Julia Base. PythonPlot should simply not plot missing data. It errors in PythonPlot.

julia> plot([1, missing, 2])
ERROR: Python: ValueError: setting an array element with a sequence.

Here is a type translation inspired by one that works for PyCall (JuliaPy/PyPlot.jl#593):

using PythonPlot
using PythonCall

"Recast julia Arrays with missing as python masked arrays."
function PythonCall.Py(a::Array{Union{T,Missing},N}) where {T,N}
    np = PythonCall.pyimport("numpy")
    np.ma.masked_invalid(np.array(replace(a, missing => NaN)))
end

# test
plot([1,2,missing,4,5], marker="o")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions