英文:
matplotlib set_yticks removes upper and lower half row of imshow
问题
When making an imshow plot using matplotlib in Python3, half of the upper and lower row is removed once I activate named yticks.
当在Python3中使用matplotlib创建imshow图时,一旦启用了命名的yticks,上半部分和下半部分的一半行都被移除了。
英文:
When making an imshow plot using matplotlib in Python3, half of the upper and lower row is removed once I activate named yticks.
See the example below:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
dummy_data = np.random.rand(5,8)
ynames = ['one','two','three','four','five']
fig = plt.figure(2)
ax = plt.gca()
im = ax.imshow(dummy_data)
plt.grid(None)
fig = plt.figure(3)
ax = plt.gca()
im = ax.imshow(dummy_data)
ax.set_yticks(np.arange(len(ynames)))
ax.set_yticklabels(ynames)
plt.grid(None)
How do I get back these upper and lower half rows?
答案1
得分: 0
当您设置y_ticks时,它会设置y轴限制。因此,再次设置ylim。
ax.set_yticklabels(ynames)
ax.set_ylim(4.5, -0.5)
就像这样。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论