python - How to add text to matplotlib legend and maintain equal space with legend and plot borders? -


i trying add text matplotlib legend can done separately adding annotation need them in single box how have done:

import numpy np import matplotlib.pyplot plt = np.array([1, 2, 3, 4, 5, 6,]) b = ** 2 c = ** 3 fig = plt.figure(1, figsize=(5, 5)) fig.clf() plot = plt.subplot(111) plot.plot(a, b, linestyle = '-', marker='^', label='quadratic') plot.plot(a, c, linestyle = '-', marker='^', label='cubic') plot.legend(title = 'lorem ipsum \n' + str(a[1]) + ' dolor sit amet,\nte dolores assentior \ninciderint iu', loc = 'center', bbox_to_anchor = (1.25, 0.5)) plot.set_ylabel('y') plot.set_xlabel('x') plt.savefig('test.pdf', bbox_inches='tight') 

and @ same time need spacing between plot , legend border same, legend width increases legend should placed further without changing loc argument, shown in figure s should constant:

+------------------------------------------------------+ |                                                      | |                                                      | |                                                      |     +----------+ |                                                      |     |          | |                                                      |  s  |          | |                                                      |<--->|          | |                                                      |     |          | |                                                      |     |          | |                                                      |     |          | |                                                      |     +----------+ |                                                      | |                                                      | |                                                      | |                                                      | |                                                      | |                                                      | |                                                      | |                                                      | |                                                      | +------------------------------------------------------+ 

is there simpler method add text in legend , keep spacing constant options of text alignment in legend box , on.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

ios - Possible to get UIButton sizeThatFits to work? -