隐藏轴标签
我试图隐藏第一个子图 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()
先感谢您。
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()
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在这里有几个不同的问题...让我将它们分解一下...
通过“隐藏第一个子图上的轴标签”您的意思是实际的轴标签(除非您指定它们,否则它们不存在),刻度标签(即沿轴的数字)、轴刻度,还是以上所有?
如果您的意思是“以上所有”,只需执行
ax.xaxis.set_visible(False)
并对 y 轴执行相同操作。 (ax
这里将是上面示例代码中的vdsvgsPlot
)如果您指的是轴刻度标签,只需将它们设置为
[]
,即:ax.set_xticklabels([])
。 (以及 y 轴的 set_yticklabels)如果您指的是轴刻度,您可以执行类似的操作:ax.set_xticks([]) 和 ax.set_yticks ([]) 这将关闭刻度线和刻度线标签。
对于第二个问题,使用
suptitle
< /a> 为整个图添加标题。即:fig.suptitle('whatever')
(上面示例代码中的f.suptitle...
)。至于如何控制字体属性,您可以将 各种关键字参数 传递给
suptitle
(或在绘图上创建文本的任何其他内容)或在创建文本后设置它们。例如fig.suptitle('This is a title', size=20,horizontalalignment='left', font='Times', color='red')
一般来说,我建议你看看通过各种用户指南,示例库(所有示例都包含源代码),pyplot api 文档,以及 d详细的 API 文档。
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. (ax
here would bevdsvgsPlot
in your example code above)If you mean the axis tick labels, just set them to
[]
, i.e.:ax.set_xticklabels([])
. (andset_yticklabels
for the y-axis)If you mean the axis ticks, you can do something similar:
ax.set_xticks([])
andax.set_yticks([])
which will turn off both the ticks and ticklabels.As to the second question, use
suptitle
to title the entire figure. i.e.:fig.suptitle('whatever')
(f.suptitle...
in your example code above).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 examplefig.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.
尝试使用
.xaxis.label.set_visible(False)
Try using
.xaxis.label.set_visible(False)
请尝试以下操作:
输出:
Please try this:
Out: