|
22 | 22 | import matplotlib.image as mimage |
23 | 23 | import matplotlib.legend as mlegend |
24 | 24 | import matplotlib.lines as mlines |
| 25 | +import matplotlib.markers as mmarkers |
25 | 26 | import matplotlib.mlab as mlab |
26 | 27 | import matplotlib.path as mpath |
27 | 28 | import matplotlib.patches as mpatches |
@@ -5651,23 +5652,8 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None, |
5651 | 5652 | *marker*: |
5652 | 5653 | can be one of: |
5653 | 5654 |
|
5654 | | - ======= ============== |
5655 | | - Value Description |
5656 | | - ======= ============== |
5657 | | - ``'s'`` square |
5658 | | - ``'o'`` circle |
5659 | | - ``'^'`` triangle up |
5660 | | - ``'>'`` triangle right |
5661 | | - ``'v'`` triangle down |
5662 | | - ``'<'`` triangle left |
5663 | | - ``'d'`` diamond |
5664 | | - ``'p'`` pentagon |
5665 | | - ``'h'`` hexagon |
5666 | | - ``'8'`` octagon |
5667 | | - ``'+'`` plus |
5668 | | - ``'x'`` cross |
5669 | | - ======= ============== |
5670 | | -
|
| 5655 | + # TODO: Use documentation in MarkerStyle |
| 5656 | + |
5671 | 5657 | The marker can also be a tuple (*numsides*, *style*, |
5672 | 5658 | *angle*), which will create a custom, regular symbol. |
5673 | 5659 |
|
@@ -5749,21 +5735,6 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None, |
5749 | 5735 |
|
5750 | 5736 | if not self._hold: self.cla() |
5751 | 5737 |
|
5752 | | - syms = { # a dict from symbol to (numsides, angle) |
5753 | | - 's' : (4,math.pi/4.0,0), # square |
5754 | | - 'o' : (0,0,3), # circle |
5755 | | - '^' : (3,0,0), # triangle up |
5756 | | - '>' : (3,math.pi/2.0,0), # triangle right |
5757 | | - 'v' : (3,math.pi,0), # triangle down |
5758 | | - '<' : (3,3*math.pi/2.0,0), # triangle left |
5759 | | - 'd' : (4,0,0), # diamond |
5760 | | - 'p' : (5,0,0), # pentagon |
5761 | | - 'h' : (6,0,0), # hexagon |
5762 | | - '8' : (8,0,0), # octagon |
5763 | | - '+' : (4,0,2), # plus |
5764 | | - 'x' : (4,math.pi/4.0,2) # cross |
5765 | | - } |
5766 | | - |
5767 | 5738 | self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs) |
5768 | 5739 | x = self.convert_xunits(x) |
5769 | 5740 | y = self.convert_yunits(y) |
@@ -5814,87 +5785,21 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None, |
5814 | 5785 | marker = (verts, 0) |
5815 | 5786 | verts = None |
5816 | 5787 |
|
5817 | | - if is_string_like(marker): |
5818 | | - # the standard way to define symbols using a string character |
5819 | | - sym = syms.get(marker) |
5820 | | - if sym is None and verts is None: |
5821 | | - raise ValueError('Unknown marker symbol to scatter') |
5822 | | - numsides, rotation, symstyle = syms[marker] |
5823 | | - |
5824 | | - elif iterable(marker): |
5825 | | - # accept marker to be: |
5826 | | - # (numsides, style, [angle]) |
5827 | | - # or |
5828 | | - # (verts[], style, [angle]) |
5829 | | - |
5830 | | - if len(marker)<2 or len(marker)>3: |
5831 | | - raise ValueError('Cannot create markersymbol from marker') |
5832 | | - |
5833 | | - if cbook.is_numlike(marker[0]): |
5834 | | - # (numsides, style, [angle]) |
5835 | | - |
5836 | | - if len(marker)==2: |
5837 | | - numsides, rotation = marker[0], 0. |
5838 | | - elif len(marker)==3: |
5839 | | - numsides, rotation = marker[0], marker[2] |
5840 | | - sym = True |
5841 | | - |
5842 | | - if marker[1] in (1,2,3): |
5843 | | - symstyle = marker[1] |
5844 | | - |
5845 | | - else: |
5846 | | - verts = np.asarray(marker[0]) |
5847 | | - |
5848 | | - if sym is not None: |
5849 | | - if symstyle==0: |
5850 | | - collection = mcoll.RegularPolyCollection( |
5851 | | - numsides, rotation, scales, |
5852 | | - facecolors = colors, |
5853 | | - edgecolors = edgecolors, |
5854 | | - linewidths = linewidths, |
5855 | | - offsets = zip(x,y), |
5856 | | - transOffset = self.transData, |
5857 | | - ) |
5858 | | - elif symstyle==1: |
5859 | | - collection = mcoll.StarPolygonCollection( |
5860 | | - numsides, rotation, scales, |
5861 | | - facecolors = colors, |
5862 | | - edgecolors = edgecolors, |
5863 | | - linewidths = linewidths, |
5864 | | - offsets = zip(x,y), |
5865 | | - transOffset = self.transData, |
5866 | | - ) |
5867 | | - elif symstyle==2: |
5868 | | - collection = mcoll.AsteriskPolygonCollection( |
5869 | | - numsides, rotation, scales, |
5870 | | - facecolors = colors, |
5871 | | - edgecolors = 'face', |
5872 | | - linewidths = linewidths, |
5873 | | - offsets = zip(x,y), |
5874 | | - transOffset = self.transData, |
5875 | | - ) |
5876 | | - elif symstyle==3: |
5877 | | - collection = mcoll.CircleCollection( |
5878 | | - scales, |
5879 | | - facecolors = colors, |
5880 | | - edgecolors = edgecolors, |
5881 | | - linewidths = linewidths, |
5882 | | - offsets = zip(x,y), |
5883 | | - transOffset = self.transData, |
5884 | | - ) |
5885 | | - else: |
5886 | | - rescale = np.sqrt(max(verts[:,0]**2+verts[:,1]**2)) |
5887 | | - verts /= rescale |
5888 | | - |
5889 | | - collection = mcoll.PolyCollection( |
5890 | | - (verts,), scales, |
| 5788 | + marker_obj = mmarkers.MarkerStyle(marker) |
| 5789 | + path = marker_obj.get_path().transformed( |
| 5790 | + marker_obj.get_transform()) |
| 5791 | + if not marker_obj.is_filled(): |
| 5792 | + edgecolors = 'face' |
| 5793 | + |
| 5794 | + collection = mcoll.PathCollection( |
| 5795 | + (path,), scales, |
5891 | 5796 | facecolors = colors, |
5892 | 5797 | edgecolors = edgecolors, |
5893 | 5798 | linewidths = linewidths, |
5894 | 5799 | offsets = zip(x,y), |
5895 | 5800 | transOffset = self.transData, |
5896 | 5801 | ) |
5897 | | - collection.set_transform(mtransforms.IdentityTransform()) |
| 5802 | + collection.set_transform(mtransforms.IdentityTransform()) |
5898 | 5803 | collection.set_alpha(alpha) |
5899 | 5804 | collection.update(kwargs) |
5900 | 5805 |
|
|
0 commit comments