Python 隐藏轴标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4079795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 14:08:23  来源:igfitidea点击:

Hiding Axis Labels

pythonmatplotlibtkinter

提问by thenickname

I'm trying to hide the axis labels on the first subplot at 211. I'd like to label the figure, not just a subplot (reference: "Isub Event Characteristics"). How can I control font properties like size, font, color?

我试图在 211 处隐藏第一个子图上的轴标签。我想标记图形,而不仅仅是子图(参考:“Isub 事件特征”)。如何控制字体属性,如大小、字体、颜色?

f = Figure()

vdsvgsPlot = f.add_subplot(211)
vdsvgsPlot.plot(theLister()[3],theLister()[0])
vdsvgsPlot.plot(theLister()[3],theLister()[1])

isubPlot = f.add_subplot(212)
isubPlot.plot(theLister()[3],theLister()[2])

plotCanvas = FigureCanvasTkAgg(f, master)
toolbar = NavigationToolbar2TkAgg(plotCanvas, master)

plotCanvas.get_tk_widget().pack()

Thank you in advance.

先感谢您。

采纳答案by Joe Kington

You have several different questions here... Let me break them up a bit...

你在这里有几个不同的问题......让我把它们分解一下......

By "hide the axis labels on the first subplot" do you mean the actual axis labels (which aren't there unless you specify them), the tick labels (i.e. the numbers along the axis), the axis ticks, or all of the above?

“隐藏第一个子图上的轴标签”是指实际的轴标签(除非您指定它们,否则不存在)、刻度标签(即沿轴的数字)、轴刻度或所有以上?

If you mean "all of the above", just do ax.xaxis.set_visible(False)and the same for the y-axis. (axhere would be vdsvgsPlotin your example code above)

如果您的意思是“以上所有”,请ax.xaxis.set_visible(False)对 y 轴执行相同的操作。(ax这里将vdsvgsPlot在您上面的示例代码中)

If you mean the axis tick labels, just set them to [], i.e.: ax.set_xticklabels([]). (and set_yticklabelsfor the y-axis)

如果您的意思是轴刻度标签,只需将它们设置为[],即:ax.set_xticklabels([])。(以及set_yticklabelsy 轴)

If you mean the axis ticks, you can do something similar: ax.set_xticks([])and ax.set_yticks([])which will turn off both the ticks and ticklabels.

如果你指的是轴刻度,你可以做同样的事情:ax.set_xticks([])ax.set_yticks([])这将同时关闭蜱ticklabels。

As to the second question, use suptitleto title the entire figure. i.e.: fig.suptitle('whatever')(f.suptitle...in your example code above).

至于第二个问题,用suptitle标题给整个图。即:fig.suptitle('whatever')f.suptitle...在你上面的例子代码)。

As for how to control the font properties, you can either pass various keyword argumentsto suptitle(or anything else that creates text on a plot) or set them after you create the text. For example fig.suptitle('This is a title', size=20, horizontalalignment='left', font='Times', color='red')

至于如何控制字体属性,您可以将各种关键字参数传递给suptitle(或在绘图上创建文本的任何其他内容)或在创建文本后设置它们。例如fig.suptitle('This is a title', size=20, horizontalalignment='left', font='Times', color='red')

In general, I would suggest you look through the various user's guide, gallery of examples(all of which have the source code included), the pyplot api docs, and the detailed api docs.

一般来说,我建议您查看各种用户指南示例库(所有这些都包含源代码)、pyplot api 文档详细的 api 文档

Hope that helps!

希望有帮助!

回答by Marcelo Villa-Pi?eros

Try using .xaxis.label.set_visible(False)

尝试使用 .xaxis.label.set_visible(False)