11

Is there a way to set default marker size (s) parameter for matplotlib plt.scatter() (or likewise to set the shape of the marker)?

mpl.rcParams.keys() has settings for the line plots, e.g.

import matplotlib as mpl
mpl.rcParams['lines.marker']='D'

... but they do not seem to relate to plt.scatter().

Thanks.

Clarification:

I'd like to use a configuration mechanism like mpl.rcParams(), or some other reasonably civilized method. Locally modifying library code is not it.

On the other hand, if it cannot currently be done and somebody submits a patch to Matplotlib, that would be awesome.

4
  • 1
    Doesn't look like this is currently configurable. Commented Oct 4, 2015 at 20:40
  • @tcaswell - That would seem like a strange omission, but it's certainly possible. I'll open a feature request issue with mpl unless somebody comes up with an answer in a couple days. Commented Oct 4, 2015 at 21:09
  • 3
    There are lots of strange omissions. github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/… <- that is the canonical list of things that can be configured via rcparams. Commented Oct 4, 2015 at 21:15
  • As of a fix pushed in March 2016, the default size of markers for scatter plots can be set - it is based on rcParams['lines.markersize'], see the commit: github.com/matplotlib/matplotlib/commit/…. Since that's the latest commit to that file, most likely there is still no way to set the default marker shape for scatter plots though (the default appears to be hardcoded as 'o'). Commented Apr 25, 2017 at 19:37

3 Answers 3

8

Of course there is, it's all in the pyplot.py

A snippet from their code:

def scatter(x, y, s=20, c=None, marker='o', cmap=None, norm=None, vmin=None,
            vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None,
            hold=None, data=None, **kwargs):

The size is set to 20 s=20 and the marker shape is a circle marker='o' which agrees with their documentation

Sign up to request clarification or add additional context in comments.

3 Comments

... not sure how this helps. My question is about setting default size; not about doing it in a particular invocation of scatter()
This is not a particular invocation, that is the default size. If you change that s value in there it'll change across all plt.scatter()
The question stated "Locally modifying library code is not it" and I guess that's what you suggest, @Leb, right?
7

In the current release, marker size is defined as:

"The marker size in points**2. Default is rcParams['lines.markersize'] ** 2."

So setting rcParams['lines.markersize'] should change the default marker size for scatterplots too now. See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html

1 Comment

ty! plt.scatter indeed respects changes made to defaults, e.g., plt.rcParams['lines.markersize'] = 1.25. Also, see matplotlib.org/stable/tutorials/introductory/customizing.html for more info :)
0

It is not possible in the current release of matplotlib (http://matplotlib.org/users/customizing.html).

However, there is an option to change the default marker in the master branch on GitHub (https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/rcsetup.py#L1112).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.