|
From: Adam H. <hug...@gm...> - 2014-03-05 19:56:52
|
Hi, I am making a stacked histogram where one must enter the desired colors together in a list/array when the histogram is called. For certain objects in my code, it's helpful to assign a color to them, so that they are immediately identified across various plots. Therefore, I essentially want to take the color cycle, swap out a few entries for which colors have been assigned by the user, and otherwise keep the cycle in tact. For example, if the first object is to be orange, but no other colors are assigned, I want something like: colors= ['orange', default_cycle[1::]] However, according to some threads, the only way to access the color cycle that I'm aware of is through a generator stored in: axes._get_lines.color_cycle() I don't like this approach because iterating through the color cycle will cause the next plot to start at a different point in the cycle. I'm sure I can hack something up that gets around this, but there seems to be a canonical way to just list all of the default colors in a list once and be done with it. Is this the case? Thanks. |
|
From: Andreas H. <li...@hi...> - 2014-03-05 20:07:52
|
On 05.03.2014 20:56, Adam Hughes wrote:> Hi, > > I am making a stacked histogram where one must enter the desired colors > together in a list/array when the histogram is called. For certain > objects in my code, it's helpful to assign a color to them, so that they > are immediately identified across various plots. Therefore, I > essentially want to take the color cycle, swap out a few entries for > which colors have been assigned by the user, and otherwise keep the > cycle in tact. For example, if the first object is to be orange, but no > other colors are assigned, I want something like: > > colors= ['orange', default_cycle[1::]] > > However, according to some threads, the only way to access the color > cycle that I'm aware of is through a generator stored in: > > axes._get_lines.color_cycle() If I'm not mistaken, you should be able to set the appropriate rcParam, i.e., mpl.rcParams['axes.color_cycle'] = ['orange', default_cycle[1::]] Cheers, Andreas. > > I don't like this approach because iterating through the color cycle > will cause the next plot to start at a different point in the cycle. > I'm sure I can hack something up that gets around this, but there seems > to be a canonical way to just list all of the default colors in a list > once and be done with it. Is this the case? > > Thanks. > > > ------------------------------------------------------------------------------ > Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce. > With Perforce, you get hassle-free workflows. Merge that actually works. > Faster operations. Version large binaries. Built-in WAN optimization and the > freedom to use Git, Perforce or both. Make the move to Perforce. > http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk > > > > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- -- Andreas. |
|
From: Adam H. <hug...@gm...> - 2014-03-05 20:07:53
|
Well, the hack wasn't as messy as I thought. Still feel like there's a
better way...
def show_colors_default():
fig, axfoo = plt.subplots()
clist = []
c = axfoo._get_lines.color_cycle.next()
# Iterate until duplicate is found
while c not in clist:
clist.append(c)
c = axfoo._get_lines.color_cycle.next()
# Reset colorcycle
for i in range(len(clist) -1):
axfoo._get_lines.color_cycle.next()
return clist
On Wed, Mar 5, 2014 at 2:56 PM, Adam Hughes <hug...@gm...> wrote:
> Hi,
>
> I am making a stacked histogram where one must enter the desired colors
> together in a list/array when the histogram is called. For certain objects
> in my code, it's helpful to assign a color to them, so that they are
> immediately identified across various plots. Therefore, I essentially want
> to take the color cycle, swap out a few entries for which colors have been
> assigned by the user, and otherwise keep the cycle in tact. For example,
> if the first object is to be orange, but no other colors are assigned, I
> want something like:
>
> colors= ['orange', default_cycle[1::]]
>
> However, according to some threads, the only way to access the color cycle
> that I'm aware of is through a generator stored in:
>
> axes._get_lines.color_cycle()
>
> I don't like this approach because iterating through the color cycle will
> cause the next plot to start at a different point in the cycle. I'm sure I
> can hack something up that gets around this, but there seems to be a
> canonical way to just list all of the default colors in a list once and be
> done with it. Is this the case?
>
> Thanks.
>
|
|
From: Adam H. <hug...@gm...> - 2014-03-05 20:13:47
|
Thanks Andreas. That is correct; however, I'd rather not make this change
global. I only want a subset of my plots to have this behavior. I feel
like changing the rcparams would change this globally and probably confuse
users who don't know this is being called.
I should have realized this before posting, but by putting this into a
function as I've shown above, the foo plot is destroyed, so it doesn't
actually appear in notebooks (which is why I was hesitant to use it in the
first place). Therefore, reseting the color cycle is not necessary and
this is all that is requried.
def show_colors_default():
axfoo = plt.subplots()[1]
c = axfoo._get_lines.color_cycle.next()
# Iterate until duplicate is found
while c not in clist:
clist.append(c)
return clist
My histogram would merely access this and be done with it.
On Wed, Mar 5, 2014 at 3:07 PM, Andreas Hilboll <li...@hi...> wrote:
> On 05.03.2014 20:56, Adam Hughes wrote:> Hi,
> >
> > I am making a stacked histogram where one must enter the desired colors
> > together in a list/array when the histogram is called. For certain
> > objects in my code, it's helpful to assign a color to them, so that they
> > are immediately identified across various plots. Therefore, I
> > essentially want to take the color cycle, swap out a few entries for
> > which colors have been assigned by the user, and otherwise keep the
> > cycle in tact. For example, if the first object is to be orange, but no
> > other colors are assigned, I want something like:
> >
> > colors= ['orange', default_cycle[1::]]
> >
> > However, according to some threads, the only way to access the color
> > cycle that I'm aware of is through a generator stored in:
> >
> > axes._get_lines.color_cycle()
>
> If I'm not mistaken, you should be able to set the appropriate rcParam,
> i.e.,
>
> mpl.rcParams['axes.color_cycle'] = ['orange', default_cycle[1::]]
>
> Cheers, Andreas.
>
>
> >
> > I don't like this approach because iterating through the color cycle
> > will cause the next plot to start at a different point in the cycle.
> > I'm sure I can hack something up that gets around this, but there seems
> > to be a canonical way to just list all of the default colors in a list
> > once and be done with it. Is this the case?
> >
> > Thanks.
> >
> >
> >
>
> ------------------------------------------------------------------------------
> > Subversion Kills Productivity. Get off Subversion & Make the Move to
> Perforce.
> > With Perforce, you get hassle-free workflows. Merge that actually works.
> > Faster operations. Version large binaries. Built-in WAN optimization
> and the
> > freedom to use Git, Perforce or both. Make the move to Perforce.
> >
>
> http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
> >
> >
> >
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
>
>
> --
> -- Andreas.
>
>
> ------------------------------------------------------------------------------
> Subversion Kills Productivity. Get off Subversion & Make the Move to
> Perforce.
> With Perforce, you get hassle-free workflows. Merge that actually works.
> Faster operations. Version large binaries. Built-in WAN optimization and
> the
> freedom to use Git, Perforce or both. Make the move to Perforce.
>
> http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
|
|
From: Goyo <goy...@gm...> - 2014-03-06 17:33:27
|
2014-03-05 21:13 GMT+01:00 Adam Hughes <hug...@gm...>:
> Thanks Andreas. That is correct; however, I'd rather not make this change
> global. I only want a subset of my plots to have this behavior. I feel
> like changing the rcparams would change this globally and probably confuse
> users who don't know this is being called.
Try using rc_context:
with plt.rc_context(rc={'axes.color_cycle': ['orange', default_cycle[1::]]}):
plt.plot(...)
This should change the color cycle only within the scope of the with
clause (not tested with this particular rcparam).
Goyo
|