Friday 15 February 2013

Python: Center plot and legend on sheet with matplotlib -



Python: Center plot and legend on sheet with matplotlib -

i have polar plot , right of legend. legend can have between 1 , 40 items length between 4 , 32 characters. goal center plot , legend if 1 object on matplotlib "sheet" (or rather empty whitespace).

i found next , adjusted needs:

import matplotlib.pyplot plt import numpy np x = np.arange(10) fig = plt.figure() ax = plt.subplot(111, polar=true) ap in aps: ax.plot(angles, ap, label="----------32-characters---------") # shrink current axis 20% box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.8, box.height]) # set legend right of current axis ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) plt.show()

the problem doesn't adjust length of labels. fits when labels 4-8 characters long shrink plot 20 % 32 character long string appear, cutting off!

what want plot + legend 1 object centered on sheet/page/empty whitespace, when there long label plot offset little bit more left in order compensate it. hope got point of trying :)

python matplotlib plot centering

No comments:

Post a Comment