StephenDonaldHuffPhD
StephenDonaldHuffPhD

Reputation: 958

Passing Scatter Plot Marker as Function Parameter in Julia Using PyPlot

I'm trying to pass the marker setting to a scatter plot in Julia using PyPlot as the backend - Julia uses the "marker=:star" syntax, for example; how do I pass this ":star" setting as a function parameter (this doesn't work as a string)?

Function Call (Doesn't Work):

   using DataFrames
   pyplot()

   df=DataFrame(someData)
   arComponents=["star","square"]
   nMaxComponents=3
   doPCA(df,arComponents,nMaxComponents)

Function Code:

# Function doPCA: performs PCA, displays scatter plot
# Inputs:  df (dataframe), arMarkers (array, plot marker settings),
#             nMaxComponents (integer, maximum # of PCA components)
#
function doPCA(df, arMarkers, nMaxComponents)
   # skipped PCA code
   nCount=1
   while nCount < nMaxComponents
      pltGet=scatter(...,marker=arMarkers[nCount],...)
      nCount=nCount+1
   end
end

Upvotes: 0

Views: 313

Answers (1)

StephenDonaldHuffPhD
StephenDonaldHuffPhD

Reputation: 958

Julia being a rather new language, the documentation is sparse and scattered, but this is essentially a PyPlot question. The scatter plot marker is a symbol, and it should be passed as such. So, the correct code to pass these data as parameters is:

Function Call (Works):

   using DataFrames
   pyplot()

   df=DataFrame(someData)
   arComponents=Symbol[:star, :square]
   doPCA(df,arComponents)

By the way, though Julia's error messages are a bit unwieldy, the hint is in the error output, wherever it reports that your bogus parameter isn't in proper Symbol[...,...] format.

Upvotes: 1

Related Questions