英文:
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)
虽然次要坐标轴是点状的,但它几乎看起来像主要坐标轴,即实线。我想知道是否有可能指定这些点之间的距离,以使它看起来不那么密集。谢谢。
英文:
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)
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论