Square Box Matplotlib

I have a graph of two boxes in one picture. For style reasons, the axis must be the same length so that the graphic square is square. I tried to use the set_aspect method, but the axes are too different due to their range and the result is terrible.

Is it possible to have 1: 1 axes even if they do not have the same number of points?

+4
source share
3 answers

Try axis('equal') . Some time has passed since I worked with matplotlib, but I seem to remember that I typed this command a lot.

+4
source

You can use Axes.set_aspect to do this if you set the aspect ratio with respect to the axes. Here is an example: alt text

 from matplotlib.pyplot import figure, show fig = figure() ax0 = fig.add_subplot(1,2,1) ax0.set_xlim(10., 10.5) ax0.set_ylim(0, 100.) ax0.set_aspect(.5/100) ax1 = fig.add_subplot(1,2,2) ax1.set_xlim(0., 1007) ax1.set_ylim(0, 12.) x0, x1 = ax1.get_xlim() y0, y1 = ax1.get_ylim() ax1.set_aspect((x1-x0)/(y1-y0)) show() 

There may be an easier way, but I don't know that.

+4
source

For log charts ( loglog() ) remember to use

 ax1.set_aspect(log10(xmax/xmin)/log10(ymax/ymin)) 
+1
source

All Articles