FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Marker/scatter reconciliation by mdboom · Pull Request #400 · matplotlib/matplotlib · GitHub

Repository navigation

11 changes: 11 additions & 0 deletions CHANGELOG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
2011-07-15 The set of markers available in the plot() and scatter()
commands has been unified. In general, this gives more
options to both than were previously available, however,
there is one backward-incompatible change to the markers in
scatter:

"d" used to mean "diamond", it now means "narrow
diamond". "D" can be used for a "diamond".

-MGD

2011-07-10 Fixed argument handling error in tripcolor/triplot/tricontour,
issue #203. - IMT

Expand Down
14 changes: 14 additions & 0 deletions examples/pylab_examples/scatter_symbol.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from matplotlib import pyplot as plt
import numpy as np
import matplotlib

x = np.arange(0.0, 50.0, 2.0)
y = x ** 1.3 + np.random.rand(*x.shape) * 30.0
s = np.random.rand(*x.shape) * 800 + 500

plt.scatter(x, y, s, c="g", alpha=0.5, marker=r'$\clubsuit$',
label="Luck")
plt.xlabel("Leprechauns")
plt.ylabel("Gold")
plt.legend(loc=2)
plt.show()
143 changes: 11 additions & 132 deletions lib/matplotlib/axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import matplotlib.image as mimage
import matplotlib.legend as mlegend
import matplotlib.lines as mlines
import matplotlib.markers as mmarkers
import matplotlib.mlab as mlab
import matplotlib.path as mpath
import matplotlib.patches as mpatches
Expand Down Expand Up @@ -5651,48 +5652,7 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
*marker*:
can be one of:

======= ==============
Value Description
======= ==============
``'s'`` square
``'o'`` circle
``'^'`` triangle up
``'>'`` triangle right
``'v'`` triangle down
``'<'`` triangle left
``'d'`` diamond
``'p'`` pentagon
``'h'`` hexagon
``'8'`` octagon
``'+'`` plus
``'x'`` cross
======= ==============

The marker can also be a tuple (*numsides*, *style*,
*angle*), which will create a custom, regular symbol.

*numsides*:
the number of sides

*style*:
the style of the regular symbol:

===== =============================================
Value Description
===== =============================================
0 a regular polygon
1 a star-like symbol
2 an asterisk
3 a circle (*numsides* and *angle* is ignored)
===== =============================================

*angle*:
the angle of rotation of the symbol

Finally, *marker* can be (*verts*, 0): *verts* is a
sequence of (*x*, *y*) vertices for a custom scatter
symbol. Alternatively, use the kwarg combination
*marker* = *None*, *verts* = *verts*.
%(MarkerTable)s

Any or all of *x*, *y*, *s*, and *c* may be masked arrays, in
which case all masks will be combined and only unmasked points
Expand Down Expand Up @@ -5749,21 +5709,6 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,

if not self._hold: self.cla()

syms = { # a dict from symbol to (numsides, angle)
's' : (4,math.pi/4.0,0), # square
'o' : (0,0,3), # circle
'^' : (3,0,0), # triangle up
'>' : (3,math.pi/2.0,0), # triangle right
'v' : (3,math.pi,0), # triangle down
'<' : (3,3*math.pi/2.0,0), # triangle left
'd' : (4,0,0), # diamond
'p' : (5,0,0), # pentagon
'h' : (6,0,0), # hexagon
'8' : (8,0,0), # octagon
'+' : (4,0,2), # plus
'x' : (4,math.pi/4.0,2) # cross
}

self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
x = self.convert_xunits(x)
y = self.convert_yunits(y)
Expand Down Expand Up @@ -5814,87 +5759,21 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
marker = (verts, 0)
verts = None

if is_string_like(marker):
# the standard way to define symbols using a string character
sym = syms.get(marker)
if sym is None and verts is None:
raise ValueError('Unknown marker symbol to scatter')
numsides, rotation, symstyle = syms[marker]

elif iterable(marker):
# accept marker to be:
# (numsides, style, [angle])
# or
# (verts[], style, [angle])

if len(marker)<2 or len(marker)>3:
raise ValueError('Cannot create markersymbol from marker')

if cbook.is_numlike(marker[0]):
# (numsides, style, [angle])

if len(marker)==2:
numsides, rotation = marker[0], 0.
elif len(marker)==3:
numsides, rotation = marker[0], marker[2]
sym = True

if marker[1] in (1,2,3):
symstyle = marker[1]

else:
verts = np.asarray(marker[0])

if sym is not None:
if symstyle==0:
collection = mcoll.RegularPolyCollection(
numsides, rotation, scales,
facecolors = colors,
edgecolors = edgecolors,
linewidths = linewidths,
offsets = zip(x,y),
transOffset = self.transData,
)
elif symstyle==1:
collection = mcoll.StarPolygonCollection(
numsides, rotation, scales,
facecolors = colors,
edgecolors = edgecolors,
linewidths = linewidths,
offsets = zip(x,y),
transOffset = self.transData,
)
elif symstyle==2:
collection = mcoll.AsteriskPolygonCollection(
numsides, rotation, scales,
facecolors = colors,
edgecolors = 'face',
linewidths = linewidths,
offsets = zip(x,y),
transOffset = self.transData,
)
elif symstyle==3:
collection = mcoll.CircleCollection(
scales,
facecolors = colors,
edgecolors = edgecolors,
linewidths = linewidths,
offsets = zip(x,y),
transOffset = self.transData,
)
else:
rescale = np.sqrt(max(verts[:,0]**2+verts[:,1]**2))
verts /= rescale

collection = mcoll.PolyCollection(
(verts,), scales,
marker_obj = mmarkers.MarkerStyle(marker)
path = marker_obj.get_path().transformed(
marker_obj.get_transform())
if not marker_obj.is_filled():
edgecolors = 'face'

collection = mcoll.PathCollection(
(path,), scales,
facecolors = colors,
edgecolors = edgecolors,
linewidths = linewidths,
offsets = zip(x,y),
transOffset = self.transData,
)
collection.set_transform(mtransforms.IdentityTransform())
collection.set_transform(mtransforms.IdentityTransform())
collection.set_alpha(alpha)
collection.update(kwargs)

Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/backend_gtk.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
from matplotlib.widgets import SubplotTool

from matplotlib import lines
from matplotlib import markers
from matplotlib import cbook
from matplotlib import verbose

Expand Down Expand Up @@ -1076,7 +1077,7 @@ class DialogLineprops:
linestyled = dict([ (s,i) for i,s in enumerate(linestyles)])


markers = [m for m in lines.Line2D.markers if cbook.is_string_like(m)]
markers = [m for m in markers.MarkerStyle.markers if cbook.is_string_like(m)]

markerd = dict([(s,i) for i,s in enumerate(markers)])

Expand Down
26 changes: 2 additions & 24 deletions lib/matplotlib/backends/qt4_editor/figureoptions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import matplotlib.backends.qt4_editor.formlayout as formlayout
from matplotlib.backends.qt4_compat import QtGui
from matplotlib import markers

def get_icon(name):
import matplotlib
Expand All @@ -25,30 +26,7 @@ def get_icon(name):
'none': 'None',
}

MARKERS = {
'none': 'None',
'o': 'circles',
'^': 'triangle_up',
'v': 'triangle_down',
'<': 'triangle_left',
'>': 'triangle_right',
's': 'square',
'+': 'plus',
'x': 'cross',
'*': 'star',
'D': 'diamond',
'd': 'thin_diamond',
'1': 'tripod_down',
'2': 'tripod_up',
'3': 'tripod_left',
'4': 'tripod_right',
'h': 'hexagon',
'H': 'rotated_hexagon',
'p': 'pentagon',
'|': 'vertical_line',
'_': 'horizontal_line',
'.': 'dots',
}
MARKERS = markers.MarkerStyle.markers

COLORS = {'b': '#0000ff', 'g': '#00ff00', 'r': '#ff0000', 'c': '#ff00ff',
'm': '#ff00ff', 'y': '#ffff00', 'k': '#000000', 'w': '#ffffff'}
Expand Down
20 changes: 17 additions & 3 deletions lib/matplotlib/collections.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ class PathCollection(Collection):
This is the most basic :class:`Collection` subclass.
"""
@docstring.dedent_interpd
def __init__(self, paths, **kwargs):
def __init__(self, paths, sizes=None, **kwargs):
"""
*paths* is a sequence of :class:`matplotlib.path.Path`
instances.
Expand All @@ -584,11 +584,25 @@ def __init__(self, paths, **kwargs):

Collection.__init__(self, **kwargs)
self.set_paths(paths)

self._sizes = sizes

def set_paths(self, paths):
self._paths = paths


def get_paths(self):
return self._paths

def get_sizes(self):
return self._sizes

@allow_rasterization
def draw(self, renderer):
if self._sizes is not None:
self._transforms = [
transforms.Affine2D().scale(
(np.sqrt(x) * self.figure.dpi / 72.0))
for x in self._sizes]
return Collection.draw(self, renderer)

class PolyCollection(Collection):
@docstring.dedent_interpd
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/legend.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from matplotlib.lines import Line2D
from matplotlib.patches import Patch, Rectangle, Shadow, FancyBboxPatch
from matplotlib.collections import LineCollection, RegularPolyCollection, \
CircleCollection
CircleCollection, PathCollection
from matplotlib.transforms import Bbox, BboxBase, TransformedBbox, BboxTransformTo, BboxTransformFrom

from matplotlib.offsetbox import HPacker, VPacker, TextArea, DrawingArea, DraggableOffsetBox
Expand Down Expand Up @@ -481,6 +481,7 @@ def _approx_text_height(self, renderer=None):
CircleCollection:legend_handler.HandlerCircleCollection(),
BarContainer:legend_handler.HandlerPatch(update_func=legend_handler.update_from_first_child),
tuple:legend_handler.HandlerTuple(),
PathCollection:legend_handler.HandlerPathCollection()
}

# (get|set|update)_default_handler_maps are public interfaces to
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/legend_handler.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,19 @@ def create_artists(self, legend, orig_handle,

return [p]

class HandlerPathCollection(HandlerRegularPolyCollection):
"""
Handler for PathCollections, which are used by scatter
"""
def create_collection(self, orig_handle, sizes, offsets, transOffset):
p = type(orig_handle)([orig_handle.get_paths()[0]],
sizes=sizes,
offsets=offsets,
transOffset=transOffset,
)
return p


class HandlerCircleCollection(HandlerRegularPolyCollection):
"""
Handler for CircleCollections
Expand Down
Loading

Back | FazBrowse Home | New Git URL