Colorplot of 2D array matplotlib

后端 未结 2 676
南方客
南方客 2021-02-06 22:01

So, I thought this was going to be really simple, but I\'ve been having a lot of difficult finding exactly what I\'m looking for in a comprehensible example.

Basically I

相关标签:
2条回答
  • 2021-02-06 22:05

    I'm afraid your posted example is not working, since X and Y aren't defined. So instead of pcolormesh let's use imshow:

    import numpy as np
    import matplotlib.pyplot as plt
    
    H = np.array([[1, 2, 3, 4],
                  [5, 6, 7, 8],
                  [9, 10, 11, 12],
                  [13, 14, 15, 16]])  # added some commas and array creation code
    
    fig = plt.figure(figsize=(6, 3.2))
    
    ax = fig.add_subplot(111)
    ax.set_title('colorMap')
    plt.imshow(H)
    ax.set_aspect('equal')
    
    cax = fig.add_axes([0.12, 0.1, 0.78, 0.8])
    cax.get_xaxis().set_visible(False)
    cax.get_yaxis().set_visible(False)
    cax.patch.set_alpha(0)
    cax.set_frame_on(False)
    plt.colorbar(orientation='vertical')
    plt.show()
    
    0 讨论(0)
  • 2021-02-06 22:24

    Here is the simplest example that has the key lines of code:

    import numpy as np 
    import matplotlib.pyplot as plt
    
    H = np.array([[1, 2, 3, 4],
              [5, 6, 7, 8],
              [9, 10, 11, 12],
              [13, 14, 15, 16]])
    
    plt.imshow(H, interpolation='none')
    plt.show()
    

    0 讨论(0)
提交回复
热议问题