本文介绍了如何在matplotlib中更改图案填充的线宽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在matplotlib中是否有增加阴影线的方法?

Is there a way to increase the width of hatch in matplotlib?

例如,以下代码通过指定linewidth仅更改边缘的宽度.我想更改用于填充的线的线宽.

For example, the following code by specifying linewidth only changes the width of the edge. I want to change the linewidth of the line used for hatch.

import matplotlib.pyplot as plt
import numpy as np

x = np.random.randn(100)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.hist(x, fill=False, hatch='/', linewidth=2)

plt.show()

推荐答案

从matplotlib 2.0版开始,您可以直接更改线宽参数,如下所示:

As of matplotlib version 2.0, you can directly change the linewidth parameter, as follows:

import matplotlib as mpl
mpl.rcParams['hatch.linewidth'] = 0.1  # previous pdf hatch linewidth
mpl.rcParams['hatch.linewidth'] = 1.0  # previous svg hatch linewidth

这似乎比上面的人员更好的解决方法.您可以通过以下方式检查matplotlib版本:

This seems a better workaround than what folks have above. You can check the matplotlib version by:

import matplotlib as mpl
print(mpl.__version__) # should be 2.x.y

这篇关于如何在matplotlib中更改图案填充的线宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:29