JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.83k stars 354 forks source link

Allow Shapes as markers, or PyPlot's rotatable markers. #2568

Open Datseris opened 4 years ago

Datseris commented 4 years ago

it would be useful for me to be able to give this "Shape" as a marker to a scatter plot. Specificlly, pass a vector of Shape as markers to scatter. That would be extremely useful.

julia> x = Shape([0.1, 0.2, 0.3], [0.1, 0.2, 0.5])
Shape([0.1, 0.2, 0.3], [0.1, 0.2, 0.5])
julia> ma = [x, x, x]
3-element Array{Shape,1}:
 Shape([0.1, 0.2, 0.3], [0.1, 0.2, 0.5])
 Shape([0.1, 0.2, 0.3], [0.1, 0.2, 0.5])
 Shape([0.1, 0.2, 0.3], [0.1, 0.2, 0.5])
julia> scatter(rand(3), rand(3), marker = ma)

(this doesn't work)

Or, at least, allow me to use PyPlot's functionality that allows rotating markers as shapes:

julia> scatter(rand(3), rand(3), marker = [(3, 0, i*90) for i in 1:3])      
┌ Warning: Skipped marker arg [(3, 0, 90), (3, 0, 180), (3, 0, 270)].
└ @ Plots C:\Users\datse\.julia\packages\Plots\XpHkc\src\args.jl:775        
julia> scatter(0.5, 0.5, marker = (3, 0, 90))
ERROR: Cannot convert Float64 to series data for plotting
Stacktrace:
 [1] error(::String) at .\error.jl:33
 [2] prepareSeriesData(::Float64) at C:\Users\datse\.julia\packages\Plots\XpHkc\src\series.jl:14
 [3] convertToAnyVector(::Float64, ::Dict{Symb

I am confused why the above doesn't work, while it would work if I did it via PyPlot.

Datseris commented 4 years ago

See https://stackoverflow.com/questions/23345565/is-it-possible-to-control-matplotlib-marker-orientation

BeastyBlacksmith commented 4 years ago

This actually should work if you use a row vector for ma consider the following:

using Plots
pgfplotsx()
x = Shape([1, 2, 3], [1, 2, 5])
ma = [x x x]
scatter(rand(3), rand(3), marker = ma, markersize = 10)

Its just that these markers are not centered. Cf. https://docs.juliaplots.org/latest/generated/pgfplotsx/#pgfplotsx-ref21-1. Better would be:

x = Shape([(-0.5, 0.), (0.5, 1.), (0.5,-1.), (-0.5,0.)])
scatter(rand(3), rand(3), markershape = x, markersize = 10)

Though for some reason passing a vector to markershape causes some displacement.