<p dir="auto">Hey.<br>
So I briefly talked with <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/tacaswell/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/tacaswell">@tacaswell</a> about this. I mostly use scatter to show a discrete third variable via color (say I plot weight vs height and want to color by gender). The current scatter is not entirely equipped for this, because it doesn't really allow me to create the legend that I want, and I doesn't allow me to use cyclers on the symbols or color.<br>
What I want can be relatively trivially implemented as a for-loop over the unique values of the discrete variable, and calling plot once for each.<br>
I use this A LOT, and other data sciency folks, too, I think, so it would be nice to have a one-liner for this, i.e. implement a function that does that for you.</p>
<p dir="auto">My question is:<br>
Should this go into matplotlib or somewhere else?<br>
If it should go into matplotlib, should it go into scatter or into a new function?</p>
<p dir="auto">currently specifying an array for color or size, only works for continuous data. using markers and colors mapped to subsets based on categorical data is hard and manual (basically you subset the data in a loop and call plot multiple times).</p>
<p dir="auto">i thought it would be hard as list-of-string already means something for some parameters (markers and colors can be specified as strings). but there is pandas’ <a href="http://pandas.pydata.org/pandas-docs/stable/categorical.html" rel="nofollow">category dtype</a>.</p>
<p dir="auto">i propose that using a categorical vector for one of these parameters should be automatically mapped to a palette of colors/markers when specified as <code class="notranslate">c</code> or <code class="notranslate">marker</code>.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# with A, B, C, being either categorical or quantitative,
# S being quantitative, and M being categorical
plt.scatter('A', 'B', s='S', c='C', marker='M', data=df)

# of course also works with arrays, and bool acts like categorical data:
plt.scatter(arr[:,0], arr[:,1], c=arr[:,-1] &gt; 0)"><pre class="notranslate"><span class="pl-c"># with A, B, C, being either categorical or quantitative,</span>
<span class="pl-c"># S being quantitative, and M being categorical</span>
<span class="pl-s1">plt</span>.<span class="pl-en">scatter</span>(<span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>, <span class="pl-s1">s</span><span class="pl-c1">=</span><span class="pl-s">'S'</span>, <span class="pl-s1">c</span><span class="pl-c1">=</span><span class="pl-s">'C'</span>, <span class="pl-s1">marker</span><span class="pl-c1">=</span><span class="pl-s">'M'</span>, <span class="pl-s1">data</span><span class="pl-c1">=</span><span class="pl-s1">df</span>)

<span class="pl-c"># of course also works with arrays, and bool acts like categorical data:</span>
<span class="pl-s1">plt</span>.<span class="pl-en">scatter</span>(<span class="pl-s1">arr</span>[:,<span class="pl-c1">0</span>], <span class="pl-s1">arr</span>[:,<span class="pl-c1">1</span>], <span class="pl-s1">c</span><span class="pl-c1">=</span><span class="pl-s1">arr</span>[:,<span class="pl-c1">-</span><span class="pl-c1">1</span>] <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span>)</pre></div>
<h2 dir="auto">more palettes than just the colormap</h2>
<p dir="auto">the color palette for categorical data would be <code class="notranslate">plt.rcParams['axes.prop_cycle'].by_key()['color']</code>, the marker palette a new <code class="notranslate">rcParam</code> (maybe?)</p>
<p dir="auto">those palettes would be cycled if there are too many categories.</p>
<h2 dir="auto">legends</h2>
<ul dir="auto">
<li>categorical: legend</li>
<li>discrete: (ordered legend or segmented bar)</li>
<li>continuous: bar (colorbar for color, isosceles trapezoid for size)</li>
</ul>
<h2 dir="auto">open questions</h2>
<ul dir="auto">
<li>are integers treated as quantitiative + discrete (legend containing all separate values) or continuous (bar)</li>
<li>how to specify if a legend/colorbar/sizebar should created? it makes sense to automatically do it if we use the <code class="notranslate">data=</code> interface</li>
</ul>