0

I am generating a colormap that plots a matrix-arranged set of data. I am using the following code:

import matplotlib.pyplot as plt                                 
%matplotlib inline

pair_kinetic=np.zeros((50,29),dtype=float)

for k in range(50):
    for m in range(29):
        pair_kinetic[k][m]=np.abs(np.sum([P[k][m][i][i+2] for i in range(37)]))/40.
plt.imshow(np.flipud(np.transpose(np.flipud(np.fliplr(pair_kinetic)))),interpolation='none',cmap=plt.cm.jet,origin='lower',extent=(-5.0,-0.1,0.0,2.8))  

plt.colorbar()
plt.title('pair kinetic energy',size=15)
plt.xlabel('$U_{1}$',size=15)
plt.ylabel('$U_{2}$',size=15)
plt.legend()
plt.show()   

As a result I get the following figure:

enter image description here

Is there a simple way to remove the grey box appearing in the top right corner?

Thank you for any help!

DavidG
  • 24,279
  • 14
  • 89
  • 82
lgotta
  • 47
  • 5
  • 1
    Remove `plt.legend()` – DavidG May 12 '20 at 12:44
  • Thank you a lot! If I may ask another question, is it possible to set the height of the legend equal to the one of the plot? – lgotta May 12 '20 at 13:05
  • 1
    Are you referring to the coloarbar? It has a parameter `shrink`. E.g. `plt.colorbar(shrink=0.7)`. A colorbar shows a range of colors with their corresponding values. A legend shows items each with a label. Note that `jet` is [considered bad for a colormap](https://jakevdp.github.io/blog/2014/10/16/how-bad-is-your-colormap/) as it unpurposeful highlights a yellow region. – JohanC May 12 '20 at 13:16
  • 1
    If you mean colourbar, then this question should help: https://stackoverflow.com/questions/18195758/set-matplotlib-colorbar-size-to-match-graph – DavidG May 12 '20 at 13:21

0 Answers0