简体   繁体   中英

Reduce Whitespace in pcolor matplotlib plot

I'm currently working on plotting pivoted tables using matplotlib pcolor but my axes are not functioning like i would like them to. I plot the tables using:

pyl.pcolor(pivot_99)
pyl.colorbar()
pyp.suptitle('Pivot 99', fontsize=14)
pyp.xlabel('Site Number', fontsize=12)
pyp.ylabel('Site Number', fontsize=12)
pyp.yticks(arange(len(pivot_99.index)),pivot_99.index)
pyp.xticks(arange(len(pivot_99.columns)),pivot_99.columns, rotation = 90)
pyl.savefig('Pivot 99.png')
pyl.show()

Where pivot_99 is a dataframe consisting of numbers between 0 and 1. The length of the index and columns are always the same but are different values for different years. When I plot pivot_99 it looks fine: 数据透视1999

However when I plot the 2000 Heatmap there is extra space on the top and right.

透视2000

Does anyone know why this is happening or how I can fix the graph so only space with color is showing? Thanks

Try with set_xlim and set_ylim like in this example:

import matplotlib.pyplot as pyp

pyp.gca().set_xlim((1,10))
pyp.gca().set_ylim((1,12))
pyp.plot([1,2],[1,2])
pyp.show()

You can try with xlim=ylim=558 , I can test it because I don't have your data :(

Alternatively, you can use prettyplotlib which will set your xlim , ylim for you automatically, remove your spines and ticks, and give you a reasonable colorbar.

import prettyplotlib as ppl
ppl.pcolormesh(pivot_99)

Full disclosure: I am the prettyplotlib author :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM