Thanks Tim for the clarification. Yes, you're right. Maybe I created the post 
basically after figuring out how to do it. But the more fundamental issue here 
is that I simply wanted to pass the color obtained from ColorBrewer directly to 
PyPlot and expected it to work out of the box. I was surprised that wasn't the 
case when I got an error message, which prompted me to dig a little further and 
do the manual conversion. Maybe this means PyPlot.jl needs to add better 
support for ColorTypes?
  
  -Islam

On Tuesday, July 5, 2016 at 1:46:18 PM UTC-4, Tim Holy wrote:
> Well, you've just written that convenience function yourself :-). It's not 
> more complicated than that.
> 
> The reason there isn't an exported function is because the general case is 
> not 
> quite as simple as it may seem. For example, BGR and RGB both mean "RGB 
> colors," but with different internal storage order. Which do you care about, 
> storage order or "meaning"? When you access a value as `red(col)`, you're 
> always getting the red channel no matter how it's stored, whereas 
> `comp1(col)` 
> might give you the red channel or might give you the blue channel. So 
> "converting to a tuple" might mean different things to different people ("red 
> first" or "component 1 first"?), which is why there's no general 
> function---it's 
> so simple to write, you might as well write it yourself, because you know 
> what 
> you want it to mean.
> 
> When you're dealing with arrays, you can always use `reinterpret` to force an 
> interpretation.
> 
> Best,
> --Tim
> 
> On Tuesday, July 5, 2016 9:59:00 AM CDT Islam Badreldin wrote:
> > Forgot to add `using ColorTypes` to the top of the minimal example.
> > 
> >   -Islam
> > 
> > On Tuesday, July 5, 2016 at 12:55:37 PM UTC-4, Islam Badreldin wrote:
> > > Hello,
> > > 
> > > I was experimenting with plotting using PyPlot and I wanted to create line
> > > plots with custom colors. I wanted to use a color palette from
> > > ColorBrewer.jl, which returns the colors as an array of ColorTypes colors.
> > > I wanted to convert the returned colors to a Tuple, e.g.
> > > (0.894,0.102,0.11), in order to pass it to PyPlot. The following snippet
> > > works for me,
> > > 
> > > 
> > > using PyPlot
> > > 
> > > using ColorBrewer
> > > 
> > > myc=palette("Set1",9)
> > > 
> > > for i in 1:9 plot(rand(100),c=(comp1(myc[i]),comp2(myc[i]),comp3(myc[i])))
> > > end
> > > 
> > > 
> > > My question is, is there a convenience function that can directly give me
> > > the desired tuple, without having to manually construct it using
> > > (comp1,comp2,comp3)?
> > > 
> > > Thanks,
> > > Islam

Reply via email to