Ask Your Question

Revision history [back]

The keywords for graphics usually end up in a dictionary called _extra_kwds. You can check to see if axes_labels and the x-axis label are given in that dictionary, and adjust your vertical displacement accordingly:

p = line([(0, 0), (1, 1)], legend_label='test', axes_labels=('X LABEL', 'Y LABEL'))

labels = p._extra_kwds.get('axes_labels')
if labels and labels[0]:
    displace = -.14 - .005 * p.fontsize()
else:
    displace = -.14

p.set_legend_options(bbox_to_anchor=(0., displace, 1., .102), loc=3, mode="expand", borderaxespad=0.)
p.show(frame=True, axes=False)

Here' a live example.