I am looking for a solution to have a seamless map image plot with matplotlib. The current code works good and stable, however, it leaves a whitespace to the left and bottom. I would like to remove this whitespace and don't know how.
My sample code for this:
import geopandas
from seaborn import despine
from pandas import read_csv
import matplotlib.pyplot as plt
# read data and shapefile
geo_path = 'shapefiles/ne_10m_admin_0_countries.shp'
df = read_csv('UNpopEstimates2100.csv')
world = geopandas.read_file(geo_path)
# specifiy what is to be plotted
cm = 'Greys'
world['2015'] = df['2015']
# set plot environment
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ax.axis('off')
plt.subplots_adjust(left=0, right=1, bottom=0, top=1)
world.plot(ax=ax, column='2015', cmap=cm, scheme='quantiles')
plt.savefig('sample.png', bbox_inches='tight', tight_layout=True, pad_inches=0, frameon=None)
smaple.png with marked whitespace I would like to remove
I followed the Tutorial at Matplotlib's Tight Layout guide, machinelearningplus.com, Removing white padding from figure on Reddit as well as several other stackoverflow posts, namely
Matplotlib scatter plot - Remove white padding,
Matplotlib: Getting subplots to fill figure,
Matplotlib plots: removing axis, legends and white spaces,
Removing white space around a saved image in matplotlib
and
matplotlib plot to fill figure only with data points, no borders, labels, axes,
What am I missing?
edit - to provide a reproducable version with non-real-life data, but question stays the same - how do I get rid of the whitespace around my plot?
I am new to Geopandas, so I am not sure how to recreate a geodataframe, however, there is built in datasets with it.
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
world['2015'] = np.random.uniform(low=1., high=100., size=(177,))
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ax.axis('off')
plt.subplots_adjust(left=0, right=1, bottom=0, top=1)
world.plot(ax=ax, column='2015', scheme='quantiles')
plt.savefig('sample.png')