python - matplotlib: get axis ratio of plot -
i need produce scatter plots several 2d data sets automatically.
by default aspect ratio set ax.set_aspect(aspect='equal')
, of times works because x,y
values distributed more or less in squared region.
sometimes though, encounter data set that, when plotted equal
ratio, looks this:
i.e.: narrow in given axis. above image, axis approximately 1:8.
in such case, aspect ratio of ax.set_aspect(aspect='auto')
result in better plot:
now, don't want set aspect='auto'
default data sets because using aspect='equal'
correct way of displaying such scatter plot.
i need fall using ax.set_aspect(aspect='auto')
only cases such 1 above.
the question: there way know before hand if aspect ratio of plot narrow if aspect='equal'
used? getting actual aspect ratio of plotted data set.
this way, based on such number, can adjust aspect ratio more sane looking (i.e.: auto
or other aspect ratio) instead of 'equal'
.
something ought do,
aspect = (max(x) - min(x)) / (max(y) - min(y))
Comments
Post a Comment