lara
lara

Reputation: 874

How to change maker in scatter plot in Julia

I would like to change the marker style of a 2D scatter plot based on the value in a vector, ultimately displaying 3 dimensions on two axes. Below is what I'd like to do and the error I get when I try it.

x = rand(1:30,100)
y = rand(20:30,100)
MyMarker = [fill("o",50);fill("x",50)]
scatter(x,y,marker=MyMarker,alpha=0.5)

LoadError: PyError (:PyObject_Call) <type 'exceptions.ValueError'>
ValueError(u"Unrecognized marker style ['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x']",)
  File "/home/lara/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/pyplot.py", line 3251, in scatter
    edgecolors=edgecolors, data=data, **kwargs)
  File "/home/lara/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/__init__.py", line 1812, in inner
    return func(ax, *args, **kwargs)
  File "/home/lara/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 3877, in scatter
    marker_obj = mmarkers.MarkerStyle(marker)
  File "/home/lara/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/markers.py", line 171, in __init__
    self.set_marker(marker)
  File "/home/lara/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/markers.py", line 252, in set_marker
    ' {0}'.format(marker))

while loading In[91], in expression starting on line 1

 in getindex at /home/lara/.julia/v0.4/PyCall/src/PyCall.jl:228
 in pysequence_query at /home/lara/.julia/v0.4/PyCall/src/conversions.jl:717
 [inlined code] from /home/lara/.julia/v0.4/PyCall/src/conversions.jl:733
 in pytype_query at /home/lara/.julia/v0.4/PyCall/src/conversions.jl:762
 in convert at /home/lara/.julia/v0.4/PyCall/src/conversions.jl:782
 in pycall at /home/lara/.julia/v0.4/PyCall/src/PyCall.jl:363
 in call at /home/lara/.julia/v0.4/PyCall/src/PyCall.jl:372
 in close_queued_figs at /home/lara/.julia/v0.4/PyPlot/src/PyPlot.jl:401

I have tried the following, neither of which is exactly what I want to do but they are close enough, and neither works.

using Plots
pyplot(size=(400,200), legend=false)  # set backend and set some session defaults
scatter(rand(30),m = ColorGradient([:red,:green,:blue]),zcolor = repmat([0,0.5,1],10))

using Plots
pyplot(size=(400,200), legend=false)  # set backend and set some session defaults
scatter(rand(30),
        m = ColorGradient([:red,:green,:blue]),  # colors are defined by a gradient
        zcolor = repmat([0,0.5,1],10) # sample from the gradient, cycling through: 0, 0.5, 1
       )

Can anyone tell me how to make marker take in a vector?

Update I have a work around but I don't like having to do this: dividing the data into separate sets and then plotting them on the same axes:

PyPlot.plot(spacerdataActualSpacer[:Length],spacerdataActualSpacer[:Curvature],marker="x",".")
PyPlot.plot(spacerdataNoActualSpacer[:Length],spacerdataNoActualSpacer[:Curvature],marker="o",".")

enter image description here

Upvotes: 1

Views: 4414

Answers (1)

Tom Breloff
Tom Breloff

Reputation: 1802

There's a few different things you can try (I'm on Plots dev, so I can't be certain what will work for you out of the box):

scatter(rand(30), group = repmat(1:3,10), marker=:auto)
scatter(rand(30), group = repmat(1:3,10), shape=[:+ :o :utri])
scatter(rand(30), group = repmat(1:3,10), shape=[:+ :o :utri], layout=(3,1))

Let me know if any of that is what you want. To be honest I'm not totally sure I know what your ideal viz will look like.

Upvotes: 2

Related Questions