【问题标题】:Filling subplot with colormap - Matplotlib LogNorm does work in python 3 anymore用颜色图填充子图 - Matplotlib LogNorm 不再适用于 python 3
【发布时间】:2021-09-09 10:06:34
【问题描述】:

我在 python 2.7 中创建了一些非常漂亮的图。

现在看来,LogNorm 不再起作用了。

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm

fig = plt.figure()
ax = fig.add_subplot(111)
        
# creating logspaced values for colorbar
x = np.logspace(-8,-3,6)
yarr = np.vstack((x,))
print(yarr)

# check if yarr is really logspaced
ax.plot(yarr, [1e1]*len(yarr), 'w.-')

# fill box with colorbar - this does not work anymore
ax.imshow(yarr, extent=(1e-8, 1e-3, 1, 1e4), norm=LogNorm(vmin=1e-8, vmax=1e-3))


ax.set_xscale("log")
ax.set_yscale("log")

立即输出

提前致谢。

【问题讨论】:

    标签: python python-3.x matplotlib


    【解决方案1】:

    有人指出这是matplotlib的问题:

    https://github.com/matplotlib/matplotlib/issues/7661/

    import numpy as np
    import matplotlib.pyplot as plt
    
    tmp = np.arange(199).reshape(1, 199)
    y = np.logspace(0, -4, 2)
    x = np.logspace(-8, -3, 200)
    
    fig, ax = plt.subplots()
    ax.set_xscale('log')
    ax.set_yscale('log')
    
    ax.pcolormesh(x, y, tmp)
    
    plt.show()
    

    这样就解决了问题。

    【讨论】:

      猜你喜欢
      • 2015-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-29
      • 1970-01-01
      相关资源
      最近更新 更多