简体   繁体   English

一个 matplotlib 样式文件可以从另一个文件继承值吗?

[英]Can one matplotlib style file inherit values from another?

Suppose I have a matplotlib style file base.mplstyle with several specifications假设我有一个 matplotlib 样式文件base.mplstyle有几个规格

legend.fancybox: True
legend.numpoints: 1
legend.frameon: True
legend.framealpha: 0.8
legend.shadow: True
text.color: white
text.usetex: True
figure.figsize : 9, 9

Suppose I want to create another style file small_figure.mplstyle , which has all identical settings save for just one:假设我想创建另一个样式文件small_figure.mplstyle ,它具有所有相同的设置,只保留一个:

legend.fancybox: True
legend.numpoints: 1
legend.frameon: True
legend.framealpha: 0.8
legend.shadow: True
text.color: white
text.usetex: True
figure.figsize : 2, 2 # <--- the only difference

Instead of copy-pasting a bunch of parameter values, is there any easy way to tell small_figure.mplstyle to inherit defaults from base.mplstyle ?有没有什么简单的方法可以告诉small_figure.mplstylebase.mplstyle继承默认值,而不是复制粘贴一堆参数值? I'm thinking something concise, like我在想一些简洁的东西,比如

# This is not a valid .mplstyle file    
plt.style.use("base")
figure.figsize : 2, 2

Style sheets are designed to be combined, so you can set up the styles you want to combine in list form.样式表旨在组合,因此您可以以列表形式设置要组合的样式。 Note, however, that they will be overridden by the values of the more right-handed styles.但是请注意,它们将被更多右手风格的值覆盖。

import matplotlib.pyplot as plt

plt.style.use(['base', 'small_figure'])

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

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