简体   繁体   English

在matplotlib中设置默认散点图标记

[英]Setting default scatter plot marker in matplotlib

I'm looking for a way to set the default marker for plt.scatter() - I've tried setting this line in my matplotlibrc file: 我正在寻找一种方法来设置plt.scatter()的默认标记 - 我已经尝试在matplotlibrc文件中设置这一行:

lines.marker    : +

but this doesn't appear to change the default marker, which is a circle. 但这似乎不会更改默认标记,即圆圈。

http://matplotlib.org/users/customizing.html doesn't seem to have any other obvious parameter to set either; http://matplotlib.org/users/customizing.html似乎没有任何其他明显的参数来设置; does anyone know if it is actually possible to set the default marker for a scatter plot? 有谁知道实际上是否可以设置散点图的默认标记?

You can do this by changing directly the code in site-packages/matplotlib/pyplot.py : 您可以通过直接更改site-packages/matplotlib/pyplot.py的代码来完成此site-packages/matplotlib/pyplot.py

# This function was autogenerated by boilerplate.py.  Do not edit as
# changes will be lost
@_autogen_docstring(Axes.scatter)
def scatter(x, y, s=20, c=None, marker='+', cmap=None, norm=None, vmin=None,
            vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None,
            hold=None, data=None, **kwargs):
    ax = gca()
    # allow callers to override the hold state by passing hold=True|False
    washold = ax.ishold()

Mind the warning in the comment since I'm not sure when boilerplate.py is being called. 注意评论中的警告,因为我不确定何时调用了boilerplate.py。 (You just need to try it out and see) However before actually changing the source consider overlapping plt.scatter with your own call: (你只需要尝试一下然后看看)但是在实际更改源代码之前,请考虑将plt.scatter与您自己的调用重叠:

import matplotlib.pyplot as plt
import numpy as np

class scatter():
    def __init__(self,x,y):
        self.marker = '+'
        plt.scatter(x,y,marker=self.marker)

x,y = np.random.randint(0,100,30),np.random.randint(0,100,30)
scatter(x,y)
plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM