half-filled markers, two-colors

I ran across:

    http://old.nabble.com/half-filled-markers-td24003576.html

The name "fillstyle" can give the wrong impression about what is being
filled. For example, see the comment here:

   http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg13074.html

It's probably too late, but would "markerfillstyle" be a better name for this?

Also, the current implementation fills half of the marker with the
markerfacecolor and doesn't fill the marker at all for the other half.
I think a neat (and simple) feature would be for users to specify two
colors. Perhaps 'markerfacecolor2'. The change to the code is
minimal, but the functionality it brings is quite flexible.
markerfacecolor2 can default to 'none' to maintain current
functionality.

Should I file a ticket for this?

I went ahead and implemented this. The user can now specify
'markercoloralt'. In the process, I finished the "half-marker" code
for all remaining filled_markers. The diff is attached, which also
includes a fix for bug #560720:

    https://sourceforge.net/tracker/?func=detail&aid=2952236&group_id=80706&atid=560720

Please comment. If there are no comments in a few days, I'll file a ticket.

A picture demonstrating this functionality is attached. Demos for all
filled markers can be obtained here:

    http://www.filedropper.com/filledmarkers

Note, the diff contains the script used to generate the pictures. More
generally, I wonder if there should be a 'markerangle' keyword. I can
probably push through and implement this, but I'd like to hear what
people think about it.

filledmarkers.diff (31.5 KB)

marker_^.png

···

On Sun, Feb 14, 2010 at 2:49 PM, T J <tjhnson@...287...> wrote:

I ran across:

http://old.nabble.com/half-filled-markers-td24003576.html

The name "fillstyle" can give the wrong impression about what is being
filled. For example, see the comment here:

http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg13074.html

It's probably too late, but would "markerfillstyle" be a better name for this?

Also, the current implementation fills half of the marker with the
markerfacecolor and doesn't fill the marker at all for the other half.
I think a neat (and simple) feature would be for users to specify two
colors. Perhaps 'markerfacecolor2'. The change to the code is
minimal, but the functionality it brings is quite flexible.
markerfacecolor2 can default to 'none' to maintain current
functionality.

Should I file a ticket for this?

TJ,

I think this current implementation and adding a marker rotation key word would be wonderful. When I get stuck doing GIS work, I end up using split markers very often. It's quite useful.

Now's probably not the time, but maybe dividing the markers up into 2, 3, or 4 sections would be useful too.
But perhaps at that point it'd be easier to create half and quarter markers and then rotate accordingly as the user makes multiple calls to plot. I dunno...just thinking aloud.

This is a great contribution. Thanks a lot!
-paul

···

-----Original Message-----
From: T J [mailto:tjhnson@…287…]
Sent: Monday, February 15, 2010 4:00 PM
To: Matplotlib Users
Subject: Re: [Matplotlib-users] half-filled markers, two-colors

On Sun, Feb 14, 2010 at 2:49 PM, T J <tjhnson@...287...> wrote:
> I ran across:
>
> http://old.nabble.com/half-filled-markers-td24003576.html
>
> The name "fillstyle" can give the wrong impression about what is being
> filled. For example, see the comment here:
>
> http://www.mail-archive.com/matplotlib-
users@lists.sourceforge.net/msg13074.html
>
> It's probably too late, but would "markerfillstyle" be a better name
for this?
>
> Also, the current implementation fills half of the marker with the
> markerfacecolor and doesn't fill the marker at all for the other half.
> I think a neat (and simple) feature would be for users to specify two
> colors. Perhaps 'markerfacecolor2'. The change to the code is
> minimal, but the functionality it brings is quite flexible.
> markerfacecolor2 can default to 'none' to maintain current
> functionality.
>
> Should I file a ticket for this?
>

I went ahead and implemented this. The user can now specify
'markercoloralt'. In the process, I finished the "half-marker" code
for all remaining filled_markers. The diff is attached, which also
includes a fix for bug #560720:

https://sourceforge.net/tracker/?func=detail&aid=2952236&group_id=80706&a
tid=560720

Please comment. If there are no comments in a few days, I'll file a
ticket.

A picture demonstrating this functionality is attached. Demos for all
filled markers can be obtained here:

    http://www.filedropper.com/filledmarkers

Note, the diff contains the script used to generate the pictures. More
generally, I wonder if there should be a 'markerangle' keyword. I can
probably push through and implement this, but I'd like to hear what
people think about it.

I ran across:

http://old.nabble.com/half-filled-markers-td24003576.html

The name "fillstyle" can give the wrong impression about what is being
filled. For example, see the comment here:

http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg13074.html

It's probably too late, but would "markerfillstyle" be a better name for this?

Also, the current implementation fills half of the marker with the
markerfacecolor and doesn't fill the marker at all for the other half.
I think a neat (and simple) feature would be for users to specify two
colors. Perhaps 'markerfacecolor2'. The change to the code is
minimal, but the functionality it brings is quite flexible.
markerfacecolor2 can default to 'none' to maintain current
functionality.

Should I file a ticket for this?

I went ahead and implemented this. The user can now specify
'markercoloralt'. In the process, I finished the "half-marker" code
for all remaining filled_markers. The diff is attached, which also
includes a fix for bug #560720:

https://sourceforge.net/tracker/?func=detail&aid=2952236&group_id=80706&atid=560720

Please comment. If there are no comments in a few days, I'll file a ticket.

A picture demonstrating this functionality is attached. Demos for all
filled markers can be obtained here:

http://www.filedropper.com/filledmarkers

Note, the diff contains the script used to generate the pictures. More
generally, I wonder if there should be a 'markerangle' keyword. I can
probably push through and implement this, but I'd like to hear what
people think about it.

Very nice and thorough work. I think this should be included, but
I'll wait to hear from other developers before committing. Could you
confirm that the unit tests pass?

import matplotlib
matplotlib.test()

I think the markerangle would also be a useful contribution, though it
would render some of the markers redundant (eg triangle left, right,
etc, would all just be triangles with different angles...)

Many thanks,
JDH

···

On Mon, Feb 15, 2010 at 5:59 PM, T J <tjhnson@...287...> wrote:

On Sun, Feb 14, 2010 at 2:49 PM, T J <tjhnson@...287...> wrote:

Very nice and thorough work. I think this should be included, but
I'll wait to hear from other developers before committing. Could you
confirm that the unit tests pass?

import matplotlib
matplotlib.test()

Confirmed on rev 8133:

Ran 124 tests in 341.585s

FAILED (KNOWNFAIL=2, errors=2)

and the errors were something to do with hexbin extents and the figimage method.

I think the markerangle would also be a useful contribution, though it
would render some of the markers redundant (eg triangle left, right,
etc, would all just be triangles with different angles...)

That was a concern I had as well, but I suppose > ^ v < (etc) could
just be considered shortcuts to particular angles. Presumably, we
would not be removing them. Correct? Also, is the standard to have
the angle specified in degrees? So what is more useful: markerangle
or markerdeg?

The other difference is that when one specifies fillstyle='left', then
it would only apply to the marker at 0 degrees. Whereas, marker='v',
fillstyle='left', markerangle=0 would correspond to marker='^',
fillstyle='right', markerangle=180 (or something like that).

···

On Mon, Feb 15, 2010 at 5:22 PM, John Hunter <jdh2358@...287...> wrote:

There's a gallery example doing that in general, making pie-charts out of the markers:

http://matplotlib.sourceforge.net/examples/api/scatter_piecharts.html

although I think my demo of it shows off its data-representation better:

# Piechart markers from matplotlib gallery, thanks to Manuel Metz for the original example
# CPHLewis, 2010.

import math
import numpy as np
import matplotlib.pyplot as plt

def payoff(x,y):
     return x*y*400

def outcome_xwins(x,y):
     return x/(x+y)

def outcome_ywins(x,y):
     return y/(x+y)

x_cases = [ .25, .5, .75]
y_cases = [ .33, .5, .66]
outcomes = [('x wins', outcome_xwins, 'blue'),
             ('y wins', outcome_ywins, 'green')] #the name, calculation, and plotting color for categories of outcome

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title('Small multiples: pie charts calculated based on (x,y)')
legend_once = True
#At each point in the plot we calculate everything about the outcomes.
for x in x_cases:
     for y in y_cases:
         size = payoff(x,y)
         start_at = 0
         for result in outcomes:
             result_share = result[1](x,y)
             xpt = [0] + np.cos(np.linspace(2*math.pi*start_at, 2*math.pi*(result_share+start_at), 10)).tolist()
             ypt = [0] + np.sin(np.linspace(2*math.pi*start_at, 2*math.pi*(result_share+start_at), 10)).tolist()
             xypt = zip(xpt, ypt)
             ax.scatter([x],[y], marker = (xypt, 0), s = size, facecolor = result[2], label=result[0])
             start_at = start_at + result_share
         if legend_once: ax.legend() #don't know why this isn't picking up the labels.
         legend_once = False
plt.show()

···

<PHobson@...2792...> wrote:

...maybe dividing the markers up into 2, 3, or 4 sections would be useful too.
...

Very nice and thorough work. I think this should be included, but
I'll wait to hear from other developers before committing. Could you
confirm that the unit tests pass?

import matplotlib
matplotlib.test()

Confirmed on rev 8133:

Ran 124 tests in 341.585s

FAILED (KNOWNFAIL=2, errors=2)
and the errors were something to do with hexbin extents and the figimage method.

Great -- I committed this patch in r8138

I think the markerangle would also be a useful contribution, though it
would render some of the markers redundant (eg triangle left, right,
etc, would all just be triangles with different angles...)

That was a concern I had as well, but I suppose > ^ v < (etc) could
just be considered shortcuts to particular angles. Presumably, we
would not be removing them. Correct? Also, is the standard to have
the angle specified in degrees? So what is more useful: markerangle
or markerdeg?

We would definitely be leaving these as shortcuts and for backward
compatibility. And yes the standard is to use degrees -- for
consistency with the text "rotation" property, we may want
markerrotation specified in degrees.

The other difference is that when one specifies fillstyle='left', then
it would only apply to the marker at 0 degrees. Whereas, marker='v',
fillstyle='left', markerangle=0 would correspond to marker='^',
fillstyle='right', markerangle=180 (or something like that).

You can think about what the right way to do this is. My first
inclination is that that left, right, etc, apply to the unrotated
marker, and then you apply the rotation. So 'd' with markerrotation=0
and fillstyle='left' would be identical to 'd' with fillstyle='right'
and markerrotation=180. But any convention you want to apply would
probably be fine as long as it is documented. Note I am not sure this
is a terribly useful feature, but it might be marginally useful and it
seems like something that could be implemented unobtrusively. So
don't kill yourself on it.

Thanks again for the nice work.

JDH

···

On Mon, Feb 15, 2010 at 8:28 PM, T J <tjhnson@...287...> wrote:

On Mon, Feb 15, 2010 at 5:22 PM, John Hunter <jdh2358@...287...> wrote:

John and T J,

L1587 at lines.py

    def set_mfc(self, val):
        'alias for set_markerfacecolor'
        self.set_markerfacecolor(val, alt=alt)

"alt" is not defined and it currently raises an exception.

By the way, I noticed that the current approach is to implement
fillstyle for EVERY markers.
An alternative approach would be using a big enough circle for
fillstyle and clip it with the full marker path.
The number of "draw_markers" call increases but the code will be much
simplified and more easy to maintain. Just a thought.

Regards,

-JJ

···

On Tue, Feb 16, 2010 at 9:39 PM, John Hunter <jdh2358@...287...> wrote:

On Mon, Feb 15, 2010 at 8:28 PM, T J <tjhnson@...287...> wrote:

On Mon, Feb 15, 2010 at 5:22 PM, John Hunter <jdh2358@...287...> wrote:

Very nice and thorough work. I think this should be included, but
I'll wait to hear from other developers before committing. Could you
confirm that the unit tests pass?

import matplotlib
matplotlib.test()

Confirmed on rev 8133:

Ran 124 tests in 341.585s

FAILED (KNOWNFAIL=2, errors=2)
and the errors were something to do with hexbin extents and the figimage method.

Great -- I committed this patch in r8138

I think the markerangle would also be a useful contribution, though it
would render some of the markers redundant (eg triangle left, right,
etc, would all just be triangles with different angles...)

That was a concern I had as well, but I suppose > ^ v < (etc) could
just be considered shortcuts to particular angles. Presumably, we
would not be removing them. Correct? Also, is the standard to have
the angle specified in degrees? So what is more useful: markerangle
or markerdeg?

We would definitely be leaving these as shortcuts and for backward
compatibility. And yes the standard is to use degrees -- for
consistency with the text "rotation" property, we may want
markerrotation specified in degrees.

The other difference is that when one specifies fillstyle='left', then
it would only apply to the marker at 0 degrees. Whereas, marker='v',
fillstyle='left', markerangle=0 would correspond to marker='^',
fillstyle='right', markerangle=180 (or something like that).

You can think about what the right way to do this is. My first
inclination is that that left, right, etc, apply to the unrotated
marker, and then you apply the rotation. So 'd' with markerrotation=0
and fillstyle='left' would be identical to 'd' with fillstyle='right'
and markerrotation=180. But any convention you want to apply would
probably be fine as long as it is documented. Note I am not sure this
is a terribly useful feature, but it might be marginally useful and it
seems like something that could be implemented unobtrusively. So
don't kill yourself on it.

Thanks again for the nice work.

JDH

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

John and T J,

L1587 at lines.py

def set_mfc(self, val):
'alias for set_markerfacecolor'
self.set_markerfacecolor(val, alt=alt)

"alt" is not defined and it currently raises an exception.

Fixed -- thanks for the catch.

By the way, I noticed that the current approach is to implement
fillstyle for EVERY markers.
An alternative approach would be using a big enough circle for
fillstyle and clip it with the full marker path.
The number, of "draw_markers" call increases but the code will be much
simplified and more easy to maintain. Just a thought.

We do some significant optimizations in the agg backend in
RendererAgg::draw_markers with cached rendered markers, so some extra
machinery would have to be pushed into the backend to continue
supporting this optimization if we wanted to follow this suggestion.

···

On Mon, Mar 1, 2010 at 8:12 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote: