我设法通过将foobar.mplstyle放入〜/ .config / matplotlib / stylelib / foobar.mplstyle
来获得自定义样式。现在我想为不同的地块设置不同的网格选项
import matplotlib.pyplot as plt
import random
plt.style.use('foobar')
plt.plot([random.random() for _ in range(50)])
plt.show()
plt.hist([random.random() for _ in range(50)])
plt.show()
在第一种情况下,我希望有完整的网格。
在直方图的情况下,我想只有水平网格线
这是可能的还是我必须创建2种样式 fooplot.mplstyle foohist.mplstyle
并做
with style.use('fooplot'):
plt.plot([random.random() for _ in range(50)])
plt.show()
with style.use('foohist'):
plt.hist([random.random() for _ in range(50)])
plt.show()
我在foobar.mplstyle文件中为水平或垂直网格线设置的确切设置是什么? 既不
grid.axis : x
,也不
grid.axis : y
,也不
grid.axis : both
似乎有用(抛出错误)
编辑:我的mplstyle文件的代码。这使得经典的水平+垂直网格工作正常。
### LINES
lines.linewidth : 1.0 # line width in points
lines.linestyle : - # solid line
lines.antialiased : True # render lines in antialised (no jaggies)
### TEXT
text.color : black
### AXES
axes.hold : True
axes.facecolor : white
axes.edgecolor : EEE2CB # axes edge color
axes.linewidth : 1.0 # edge linewidth
axes.grid : True # display grid or not
axes.titlesize : large # fontsize of the axes title
axes.labelsize : medium # fontsize of the x any y labels
axes.labelweight : normal # weight of the x and y labels
axes.labelcolor : k
axes.axisbelow : False # whether axis gridlines and ticks are below
# the axes elements (lines, text, etc)
axes.formatter.use_locale : True # When True, format tick labels
# according to the user's locale.
# For example, use ',' as a decimal
# separator in the fr_FR locale.
axes.color_cycle : 95c11f, 1f94d2, e5004b, 28b195, black # color cycle for plot lines
### TICKS
xtick.color : k # color of the tick labels
ytick.color : k
xtick.major.size : 0
xtick.minor.size : 0
ytick.major.size : 0
ytick.minor.size : 0
### GRIDS
grid.linestyle : - # dotted
grid.linewidth : 2 # in points
grid.alpha : 0.5 # transparency, between 0.0 and 1.0
grid.color : eee2cb
### Legend
legend.frameon : False # whether or not to draw a frame around legend