I am creating graphs in python's matplotlib using contourf and I want to know if there is anyway to set the size of the pixel size to create a "flexible" plot size. The program I am creating will have user generated data that could mean the matrix I am using to plot could be as big as [693][983] or as small as [10][10]. The problem I am having is that matplotlib/contourf defaults to a square grid which means I get a lot of "stretching" if say my matrix size is [100][700]. I want to know if I can create a flexible grid size to fix this problem. Here is my current code.
def PlotCreation2(Matrix, MinY, MaxY, X, Y, Lvl, Zeta):
fig, ax = plt.subplots()
Intervals = (MaxY - MinY) / 50
if (Intervals == 0):
MaxY = MaxY +1
MinY = MinY -1
Intervals = (MaxY - MinY) / 50
contour_levels = arange(MinY,MaxY,Intervals)
cs = ax.contourf(X, Y, Matrix, contour_levels)
cbar = plt.colorbar(cs)
plt.savefig(('plt%d.png') %(Zeta*1000+Lvl))
print(("Image number %d has been created") %Zeta)
I this case the Matrix could be anysize but the meshgrid from X and Y will always match the Matrix. Don't worry about the Lvl or Zeta variables, I just use them to name the image I save.