`matplotlib` 的 `set_yticks` 移除了 `imshow` 的上半部和下半部行。

huangapple go评论70阅读模式
英文:

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)

`matplotlib` 的 `set_yticks` 移除了 `imshow` 的上半部和下半部行。

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)

就像这样。

英文:

When you set y_ticks it set y limit. Therefore, set ylim again.

ax.set_yticklabels(ynames)
ax.set_ylim(4.5,-0.5)

like this.

`matplotlib` 的 `set_yticks` 移除了 `imshow` 的上半部和下半部行。

huangapple
  • 本文由 发表于 2020年1月6日 17:25:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609535.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定