Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib write text in the margin

If I make a graph using pylab from matlotlib like so...

import pylab as p
x = [0,1,2]
y = [2,4,6]
p.plot(x,y)
p.show()

I want to use the p.text function to add text to the graph. However, I want to put the text in the margin outside of the data window. The text function only accepts x,y coordinates that correspond to the data points rather than absolute x,y pixels coordinates of the entire window. Any idea how I can write text in the margins?

like image 687
eat_a_lemon Avatar asked Mar 28 '11 19:03

eat_a_lemon


People also ask

What is padding in Matplotlib?

pad: This parameter is used for padding between the figure edge and the edges of subplots, as a fraction of the font size. h_pad, w_pad: These parameter are used for padding (height/width) between edges of adjacent subplots, as a fraction of the font size.


1 Answers

You can use the figtext function. Only note that the coordinates are 0-1, so something like the following places text to the left of the vertical axis:

p.figtext(0.05, 0.5, 'foo')

See the linked docs for more information.

like image 87
ars Avatar answered Sep 22 '22 13:09

ars