AxesSubplot 对象的 xticks 的等效函数
所以我尝试使用 Axes 对象来控制我的 matlibplot 图。我没有使用 plt (又名 import matlibplot.pyplot as plt),因为我将图形嵌入到我的 tkinter GUI 中 这个。
但是,我也在图中使用了子图,所以类似于:
a = f.add_subplot(121)
a2 = f.add_subplot(122)
a.plot(fn2,mag)
a2.bar(range(0,10), magBin, width)
这一切都很好,我可以使用坐标区属性来控制事物(即 a.axesMethod()
),但我想要我的条形图的字符串标签,根据这个,请参阅代码。
我的困境是我不能使用
plt.xticks(ind+width, ('G1', 'G2', 'G3', 'G4', 'G5') )
示例中的 As,因为如果我想将它嵌入到我的 Tkinter GUI 中,我就不能使用 plt。我只能使用 Axes 对象做一些事情。我正在尝试使用 a2.set_xticks
,但这不允许将字符串用作条形图所需的刻度功能。
So I am trying to use Axes objects to control my matlibplot figure. I am not using plt (aka import matlibplot.pyplot as plt) because I am embedding the figure in my tkinter GUI per this.
However, I am also using subplots in the figure, so something like:
a = f.add_subplot(121)
a2 = f.add_subplot(122)
a.plot(fn2,mag)
a2.bar(range(0,10), magBin, width)
This is all well and good, I can use the axes properties to control things (i.e. a.axesMethod()
), but I want string labels for my bar plots, per this, see code.
My dilemma is that I cannot use
plt.xticks(ind+width, ('G1', 'G2', 'G3', 'G4', 'G5') )
As in the example, because I cannot use plt
if I want to embed it into my Tkinter GUI. I am limited to what I can do with Axes objects. I am trying to use a2.set_xticks
, but this does not allow for the string as ticks functionality I need for my bar chart.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以使用:
和
you can use instead:
and
从 matplotlib 3.5.0 开始,您可以将标签作为第二个参数传递给 ax.set_xticks()(第一个参数是刻度位置),就像使用 plt.xticks( )。因此,一个有效的示例是:
您也可以使用
set()
:需要注意两件事:(a)
len(ticks)==len(labels)
应该是正确,并且 (b) 要在整个轴上充分分布 xticks,请使用 ax.get_xlim() 获取 x 轴刻度的限制并创建从以下位置开始和结束的值范围:限制。因此,一个有效的示例可能是:Since matplotlib 3.5.0, you can pass labels as the second argument to
ax.set_xticks()
(the first argument is the tick locations), the same way you would withplt.xticks()
. So a working example would be:You can use
set()
as well:Two things to note: (a)
len(ticks)==len(labels)
should be True, and (b) to adequately spread out the xticks across the whole axis, useax.get_xlim()
to get the limits of the x-axis ticks and create a range of values starting and ending at the limits. So a working example could be: