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
Post a Comment