简体   繁体   English

Matplotlib:有没有办法用 matplotlibrc 设置默认散布 styles?

[英]Matplotlib: Is there a way to set default scatter styles with matplotlibrc?

I do a fair amount of plotting with pandas and matplotlib, and I've been looking for a way to help set the default scatter styles in my matplotlibrc file.我使用 pandas 和 matplotlib 进行了大量绘图,并且我一直在寻找一种方法来帮助在我的 matplotlibrc 文件中设置默认散点图 styles。 I do not want to have to edit the matplotlib sourcecode to get default behaviors, because I need to be able to allow coworkers to reproduce work (and want to keep things consistent between machines/VEs, and update without worrying about busting things).我不想编辑 matplotlib 源代码来获得默认行为,因为我需要能够允许同事重现工作(并且希望在机器/VE 之间保持一致,并在不担心破坏的情况下进行更新)。

As an example, I want to be able to do:例如,我希望能够做到:

plt.scatter(
    df["dep_var"],
    df["ind_var"],
    alpha=0.5,
    facecolors="none",
    edgecolors="#444444",
    linewidth=2,
)

With:和:

plt.scatter(
    df["dep_var"],
    df["ind_var"],
)

With overwritten alpha, face colors, edge colors, and linewidth in the matplotlibrc file (or some other non-source code location).在 matplotlibrc 文件(或其他一些非源代码位置)中覆盖 alpha、面 colors、边缘 colors 和线宽。 But when I add但是当我添加

scatter.alpha : 0.5 

to my matplotlibrc file, I get a Bad Key warning.到我的 matplotlibrc 文件,我得到一个坏键警告。

Is there a way to achieve this?有没有办法做到这一点?

I think that a possible solution is use the RC parameter like:我认为一个可能的解决方案是使用 RC 参数,如:

plt.rcParams["scatter.edgecolors"] = "#444444"
plt.rcParams["lines.linewidth"]=2

You can check more about ket for Rc here你可以在这里查看更多关于 ket for Rc

You only need to run this once.您只需要运行一次。 If you restart the kernel it will be reverted to the default.如果您重新启动 kernel,它将恢复为默认值。

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

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