设置matplotlib中网格线上点之间的距离

huangapple go评论78阅读模式
英文:

Setting the distance between dots on grid lines in matplotlib

问题

以下是翻译好的部分:

我正在绘制一个带有主要和次要坐标轴网格的matplotlib图形。此外,我已将次要坐标轴线型设置为":",以便网格线是点而不是实线。但是这些点非常密集,很难区分。是否有任何方法可以控制这些点之间的间距?
以下是我的代码:

import matplotlib.pyplot as plt

plt.grid(which='major', linewidth='0.7')
plt.grid(which='minor', linewidth='0.7', ls=":")
plt.semilogy(np.linspace(-4, 20, 25), some_data, 'C1', marker='o', markersize=20)

我得到了以下图形:
设置matplotlib中网格线上点之间的距离

虽然次要坐标轴是点状的,但它几乎看起来像主要坐标轴,即实线。我想知道是否有可能指定这些点之间的距离,以使它看起来不那么密集。谢谢。

英文:

I am plotting a matplotlib graph with grid along both major and minor axis. Also I have set the minor axis line style to ":", so that grid lines are dots instead of solid line. But the dots are very closely spaced, that it is hard to differentiate. Is there any way to control the spacing between these dots?
Following is my code:

import matplotlib.pyplot as plt

plt.grid(which='major', linewidth='0.7')
plt.grid(which='minor', linewidth='0.7', ls=":")
plt.semilogy(np.linspace(-4, 20, 25), some_data, 'C1', marker='o', markersize=20)

I get the following graph
设置matplotlib中网格线上点之间的距离

Though the minor axis is dotted it looks almost like the major axis, which is solid line. I want to know if it is possible to specify this distance between the dots so that it would look a little less dense. Thanks.

答案1

得分: 2

The dashes parameter/argument lets you specify that.

plt.grid(which='minor', linewidth='0.7', ls=":", dashes=(1,10,1,10))

dashes is a Line2D property so you should be able to set the spacing for any Line2D artist.

英文:

The dashes parameter/argument lets you specify that.

plt.grid(which='minor', linewidth='0.7', ls=":", dashes=(1,10,1,10))

dashes is a Line2D property so you should be able to set the spacing for any Line2D artist.

huangapple
  • 本文由 发表于 2020年1月3日 21:23:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/59579354.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定