简体   繁体   English

Matplotlib图,带有更细的刻度线,但没有标签

[英]Matplotlib Plot with Finer tick marks but no labels

在此处输入图片说明 I am trying to produce a plot where I have customized axis ticks on both x and y axis. 我正在尝试绘制一个在x和y轴上都已自定义轴刻度的图。 But like in a scale, I would like to have the finer tick marks present while the tick markings only on the bigger values. 但是像刻度尺一样,我希望有较细的刻度线,而刻度线仅在较大的值上。 Like shown in the attached plot(which is similar to what I want). 就像附件中的图所示(类似于我想要的)。

so I tried : 所以我尝试了:

ax.tick_params(labeltop=True, labelright=True)

Because I need the ticks on all 4 sides. 因为我需要所有四个方面的刻度。 and then I would do something like this : 然后我会做这样的事情:

ax.yaxis.set_ticks_position('both')
ax.xaxis.set_ticks_position('both') 

and then specify the range : 然后指定范围:

plt.xticks(np.arange(-1.20, -0.79, 0.04))
plt.yticks(np.arange(-1.0,1.2, 0.1))

But I would like the numerical markings every 5th position (or every 5th tick) 但我希望每5个位置(或每5个刻度)有数字标记

Here's My solution : (thanks @Diziet) 这是我的解决方案:(感谢@Diziet)

from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,AutoMinorLocator)   
# Plotting codes go in here
ax.yaxis.set_ticks_position('both')# Ticks on all 4 sides                                                                                                                                                                                                                                    
ax.xaxis.set_ticks_position('both')                                                                                                                                                                                                                                    
plt.xticks(np.arange(-1.21, -0.79, 0.04)) # Axes ranges                                                                                                                                                                                                                             
plt.yticks(np.arange(-0.9,0.9, 0.1))                                                                                                                                                                                                                                   
ax.xaxis.set_major_locator(MultipleLocator(0.05)) # Intervals for major x-ticks                                                                                                                                                                                                                     
ax.xaxis.set_minor_locator(AutoMinorLocator()) # Minor ticks : Automatic filling based on the ytick range                                                                                                                                                                                                                        
ax.yaxis.set_major_locator(MultipleLocator(0.3))  # For y-ticks                                                                                                                                                                                                                     
ax.yaxis.set_minor_locator(AutoMinorLocator())       

Attached is the Final product 附件是最终产品 用细刻度画

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

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