简体   繁体   English

使用matplotlib.axis.XAxis.set_ticks_position('bottom')时发生Python Matplotlib错误

[英]Python Matplotlib error when using matplotlib.axis.XAxis.set_ticks_position('bottom')

I am using the Enthought IDE for Python, and I'm plotting a matrix named recmat using matshow. 我正在使用面向Python的Enthought IDE,并且正在使用matshow绘制一个名为recmat的矩阵。 Matshow plots the xlabes on top of the plot, I'd like them to be on the bottom. Matshow将xlab绘制在图的顶部,我希望它们在底部。 The code below leads to this error message: 下面的代码导致此错误消息:

TypeError: set_ticks_position() missing 1 required positional argument: 'position' TypeError:set_ticks_position()缺少1个必需的位置参数:“ position”

plt.matshow(recmat)
matplotlib.axis.XAxis.set_ticks_position('bottom')
plt.colorbar()
plt.show()

How can I fix this? 我怎样才能解决这个问题? Or is there another way to move the labels? 还是有另一种移动标签的方法? Thanks a lot for your help! 非常感谢你的帮助!

You need to call xaxis.tick_bottom() for the current axes as shown below: 您需要为当前轴调用xaxis.tick_bottom() ,如下所示:

import numpy as np
import matplotlib.pyplot as plt

recmat = np.random.random((100,100))
plt.matshow(recmat)

ax = plt.gca()
plt.colorbar()
ax.xaxis.tick_bottom()

plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM