numpy - unevenly centered subplots in matplotlib in Python? -


I have a simple couple's weekly in matplotlib which is unevenly centered for some reason. Let me tell them this way:

  plt.figure () # first subplot s1 = plt.subplot (2, 1, 1) plt.bar ([1, 2, 3], [ 4], 5, 6]) # seconds subplot s2 = plt.subplot (2, 1, 2) plt.pcolor (rand (5,5)) # add color bar plt.colorbar () # square axes axes_square (s1) Axes_square (s2)  

where axes_square is just:

  def axes_square (plot_handle): plot_handle.axes.set_aspect (1 / plot_handle.axes.get_data_ratio ( ))  

The attachment I get is enclosed. Top and bottom plots are uneven centered. I want their yaxis to be aligned and their boxes should be combine.

If I remove the plt.colorbar () call, the plots become centered. How can i be plots centered while the colorbar of pcolor is still shown? I want the axes to be centered and the colors are out of that alignment, either on the left or on the right side of the pcolor matrix.

> Thanks.

OK, this is probably not what you want, but it will work:

  numpy.random import rand import matplotlib.pyplot plt plt.figure () # first subplot s1 = plt.subplot (2, 2, 2) plt.bar ([1, 2], 3] , [4, 5, 6]) # seconds subplot s2 = plt.subplot (2, 2, 4) plt.pcolor (rand (5,5)) # square axes axes_square (s1) axes_square (s2) s_fake = plt Subplot (2, 2, 3) s_fake.set_axis_off () # add color bar plt.colorbar ()  

This just makes a fake pair on the left, and does not have them in None displayed too good Land, but it works. ;)

In addition, I guess these two imports were contained in your code ...


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -