如何从图中删除Xticks
我有一个Semilogx情节,我想删除Xticks。我尝试了:
plt.gca().set_xticks([])
plt.xticks([])
ax.set_xticks([])
网格消失(可以),但是小tick(在主壁虱的位置)仍然存在。如何删除它们?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
请注意,还有 ax.tick_params 对于
matplotlib.axes.axes.axes
对象。The
plt.tick_params
method is very useful for stuff like this. This code turns off major and minor ticks and removes the labels from the x-axis.Note that there is also
ax.tick_params
formatplotlib.axes.Axes
objects.并不是完全要求OP要求的,而是一种禁用所有轴线,tick和标签的简单方法就是简单地致电:
Not exactly what the OP was asking for, but a simple way to disable all axes lines, ticks and labels is to simply call:
另外,您可以将空的刻度位置传递给
Alternatively, you can pass an empty tick position and label as
这是我在:
Here is an alternative solution that I found on the matplotlib mailing list:
有一个比约翰·维尼德(John Vinyard)提供的更好,更简单的解决方案。使用
nulllocator
:There is a better, and simpler, solution than the one given by John Vinyard. Use
NullLocator
:尝试删除标签(而不是tick):
example
Try this to remove the labels (but not the ticks):
example
该片段可能有助于删除Xticks。
该片段可能有助于消除Xticks和yticks。
This snippet might help in removing the xticks only.
This snippet might help in removing the xticks and yticks both.
你们中的那些正在寻找一个简短命令来关闭所有tick和标签的
那些应该可以使用
bool
用于各自参数的类型,因为版本matplotlib> = 2.1.1对于自定义滴答设置,文档很有帮助。 :
httpps://matplotlib.orgg/apib.orpi/api/_as_as_gen/matplib.axes-.arplib.axes..ar> https:/ axes.tick_params.html
Those of you looking for a short command to switch off all ticks and labels should be fine with
which allows type
bool
for respective parameters since version matplotlib>=2.1.1For custom tick settings, the docs are helpful:
https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.tick_params.html
可以简单地更改可见性:
ax.xaxis.set_visible(false)
It is possible to simply change the visibility:
ax.xaxis.set_visible(False)
Modify the following rc parameters by adding the commands to the script:
A sample matplotlibrc file is depicted in
Modify the following rc parameters by adding the commands to the script:
A sample matplotlibrc file is depicted in this section of the matplotlib documentation, which lists many other parameters like changing figure size, color of figure, animation settings, etc.
如果您想删除tick标签,但要保留tick和网格,则此代码段将起作用。
If you want to remove tick labels but keep the ticks and grids, this code snippet will work.
解决此问题的一个简单解决方案是将
Xticks
的颜色设置为白色或背景颜色的任何内容。这将隐藏Xticks的文字,而不是Xticks本身。结果
A simple solution to this problem is to set the color of the
xticks
to White or to whatever the background color is. This will hide the text of the xticks but not the xticks itself.Result