This is the structure of my data:
print("test_data: " + str(test_data))
#test_data: [[-1.3869276 0.76189806]
# [-1.3870304 0.76177611]
# [-1.38695643 0.76194005]
# ...,
# [-1.38663699 0.76174211]
# [-1.38670514 0.76161662]
# [-1.3865974 0.76163099]]
It is a numpy array of lat/lng coordinates converted to radians.
I have problems setting the x and y limits/bounds of the matplot-figure. I have tried both set_xlim()
/set_ylim()
and set_xbound()
/set_ybound()
, but the results are not satisfactory:
set_xlim()
and set_ylim()
result in a distorted view of my data:
.. while set_xbound()
and set_ybound()
zooms in too much (and further crops labels of the y-axis):
This is my code:
test_data = np.radians(points)
#get max data extent
limXMin = np.max(test_data[0])
limXMax = np.max(test_data[1])
limYMax = np.min(test_data[0])
limYMin = np.min(test_data[1])
#print max data extent:
print(limXMin)
print(limXMax)
print(limYMin)
print(limYMax)
#0.761924200543
#0.761882818787
#-1.38701148104
#-1.3868174877
#create figure
fig = plt.figure(figsize=(11, 8), dpi=80)
#print current extent
print(str(plt.xlim()))
print(str(plt.ylim()))
#(0.0, 1.0)
#(0.0, 1.0)
ax = fig.add_subplot(1,1,1) # 1 Row, 1 Column and the first axes in this grid
plt.scatter(test_data.T[0], test_data.T[1], color='b', **plot_kwds)
#modify extent (Fig.1)
ax.set_xlim([limXMin, limXMax])
ax.set_ylim([limYMin, limYMax])
#modify extent (Fig.2)
ax.set_xbound(limXMin, limXMax)
ax.set_ybound(limYMin, limYMax)
ax.figure.savefig(pathname + '/graph_1.png')
Instead, if I do this:
plt.figure(figsize=(11, 8), dpi=80)
plt.autoscale(enable=True)
fig = plt.scatter(test_data.T[0], test_data.T[1], color='b', **plot_kwds)
fig.figure.savefig(pathname + '/graph_1.png')
I get the full extent but with too much border. Almost half of the plot area is not showing data: