本文介绍了隐藏轴标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

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()

谢谢.

推荐答案

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

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?

如果您的意思是以上所有内容",则只需执行ax.xaxis.set_visible(False),并且对y轴也是如此. (ax在上面的示例代码中为vdsvgsPlot)

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

如果要表示轴刻度标签,只需将它们设置为[],即:ax.set_xticklabels([]). (Y轴为set_yticklabels

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

如果您指的是轴刻度,则可以执行类似的操作:ax.set_xticks([])ax.set_yticks([]),这将同时关闭刻度和刻度标签.

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.

对于第二个问题,请使用 suptitle 为整个图加上标题.即:fig.suptitle('whatever')(在上面的示例代码中为f.suptitle...).

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

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

As for how to control the font properties, you can either pass various keyword arguments to 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')

通常,我建议您仔细阅读各种用户指南示例库(均包含源代码), pyplot api文档和d 详细的api文档.

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.

希望有帮助!

这篇关于隐藏轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 04:14