JuliaPy / PyPlot.jl

Plotting for Julia based on matplotlib.pyplot
https://github.com/JuliaPy/PyPlot.jl
MIT License
475 stars 87 forks source link

surf() failing when broadcasting is needed #400

Closed IanButterworth closed 5 years ago

IanButterworth commented 5 years ago

The following is currently failing in Julia 1.0.1

using PyPlot
x = -5:0.25:5
y = x'
z = sin.(sqrt.(x.^2 .+ y.^2))
surf(x,y,z)

MethodError: no method matching strides(::LinearAlgebra.Adjoint{Float64,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}})
Closest candidates are:
  strides(!Matched::SubArray) at subarray.jl:264
  strides(!Matched::Base.CodeUnits) at strings/basic.jl:696
  strides(!Matched::PermutedDimsArray{T,N,perm,iperm,AA} where AA<:AbstractArray where iperm) where {T, N, perm} at permuteddimsarray.jl:62
  ...

Stacktrace:
 [1] stride(::LinearAlgebra.Adjoint{Float64,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Int64) at ./abstractarray.jl:342
 [2] array2py(::LinearAlgebra.Adjoint{Float64,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Int64, ::Int64) at /Users/IanB/.julia/packages/PyCall/0jMpb/src/conversions.jl:305
 [3] array2py(::LinearAlgebra.Adjoint{Float64,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}) at /Users/IanB/.julia/packages/PyCall/0jMpb/src/conversions.jl:325
 [4] Type at /Users/IanB/.julia/packages/PyCall/0jMpb/src/conversions.jl:327 [inlined]
 [5] macro expansion at /Users/IanB/.julia/packages/PyCall/0jMpb/src/exception.jl:84 [inlined]
 [6] _pycall!(::PyCall.PyObject, ::PyCall.PyObject, ::Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},LinearAlgebra.Adjoint{Float64,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}},Array{Complex{Float64},2}}, ::Int64, ::Ptr{Nothing}) at /Users/IanB/.julia/packages/PyCall/0jMpb/src/pyfncall.jl:21
 [7] _pycall!(::PyCall.PyObject, ::PyCall.PyObject, ::Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},LinearAlgebra.Adjoint{Float64,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}},Array{Complex{Float64},2}}, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/IanB/.julia/packages/PyCall/0jMpb/src/pyfncall.jl:11
 [8] #pycall#88(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::PyCall.PyObject, ::Type{PyCall.PyAny}, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Vararg{Any,N} where N) at /Users/IanB/.julia/packages/PyCall/0jMpb/src/pyfncall.jl:86
 [9] pycall(::PyCall.PyObject, ::Type{PyCall.PyAny}, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Vararg{Any,N} where N) at /Users/IanB/.julia/packages/PyCall/0jMpb/src/pyfncall.jl:86
 [10] #plot_surface#170(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Vararg{Any,N} where N) at /Users/IanB/.julia/packages/PyPlot/fZuOQ/src/plot3d.jl:50
 [11] plot_surface at /Users/IanB/.julia/packages/PyPlot/fZuOQ/src/plot3d.jl:48 [inlined]
 [12] #surf#182 at /Users/IanB/.julia/packages/PyPlot/fZuOQ/src/plot3d.jl:78 [inlined]
 [13] surf(::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::LinearAlgebra.Adjoint{Float64,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Array{Complex{Float64},2}) at /Users/IanB/.julia/packages/PyPlot/fZuOQ/src/plot3d.jl:78
 [14] top-level scope at In[84]:6
lnacquaroli commented 5 years ago

See https://github.com/JuliaPy/PyPlot.jl/issues/362 and https://github.com/JuliaPy/PyPlot.jl/issues/391.

You could also do y = Matrix(x') for surfto work.

stevengj commented 5 years ago

Closed by https://github.com/JuliaPy/PyCall.jl/pull/653