0

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.

Justin Jones
  • 361
  • 1
  • 3
  • 7
  • It's not clear what you mean by "flexible grid size". Please describe the plot you get (best provide a [mcve]) and the plot you want to have. – ImportanceOfBeingErnest Jun 27 '17 at 18:38
  • contourf defaults to displaying a square plot. This works fine if my matrix is or is close to a square (say 100x100) but how might is display the plot as a rectangle? (say when my matrix is 100x700?) – Justin Jones Jun 29 '17 at 12:42
  • No, contourf, like most other plots, except imshow or matshow, displays in a rectangular subplot, whose size is completely independend on the data. I can only repeat myself: Please provide a [mcve] and a clear problem description of what you get and what you'd expect instead. – ImportanceOfBeingErnest Jun 29 '17 at 13:19

0 Answers0