rustychris/stompy

UnstructuredGrid.plot_cells() axis bounds broken

Closed this issue · 2 comments

When trying to plot the collection of cells the axis incorrectly gets set with xlim/ylim of [0,1]. I see that the function request_square() was employed; however, it doesnt seem to work with the updated matplotlib (this is my guess).

Regardless, for those who have had trouble, the following is a sufficient solution for general plotting purposes:

minx, miny = np.min(nodes[:, 0]), np.min(nodes[:, 1])
maxx, maxy = np.max(nodes[:, 0]), np.max(nodes[:, 1])
ax.set_xlim([minx, maxx])
ax.set_ylim([miny, maxy])

This will set the axis limited to the widest extent necessary to show all of the grid faces. Hope this helps if anyone was struggling.

Thanks for the tip! A little background in case it helps:
This is related to newer matplotlib and shared axes. When two or more axes have sharex and sharey enabled, matplotlib will complain if the axes are also set to equal aspect ratio. This is because, within the assumptions of the layout engine, the problem becomes overdetermined. request_square() is a half-solution that needs some more work and testing. That said, plot_cells() should work the same as plot_edges and plot_nodes, and it didn't. That should be fixed as of commit 4542ef6.

If updating is too annoying and you don't have any shared axes, another quick solution is a call to ax.axis('equal').

If this doesn't work, or somebody knows a better solution please re-open this issue.

Thanks!