0

How can we had special data next to a matplotlib figure For example

fig, ax = plt.subplots()
plt.legend()
plt.title()
plt.annotate()

Is there a way to put a box next the plot with additionnal data (I mean real textual comments ,....)

enter image description here

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sylvain Page
  • 581
  • 1
  • 7
  • 21

3 Answers3

4

You can use matplotlib's text function.

#data is your normal string variable only.
data = ( 'CPK = \n'
'Cp = \n'
... # Rest of your text 
)
plt.text(1.20,0,data)

The syntax is plt.text(x_co-ordinate,y_co-ordinate,string_to_print). The figure is ([0-1],[0-1])

Spandan Brahmbhatt
  • 3,774
  • 6
  • 24
  • 36
  • yes, thanks. Just put what I finally did. Is ([0-1],[0,1]) the general system coordinate for figure ? I made a quick calculation to be 10% far from the plot (see answer below) – Sylvain Page Mar 02 '17 at 08:19
  • If you really need a lot of info, `table` can also be useful, although a bit more work: http://matplotlib.org/examples/pylab_examples/table_demo.html – Rutger Kassies Mar 02 '17 at 08:28
0

Finally it works like this for me :

dict = OrderedDict()
dict['key1'] = stuff
dict['keyn'] = stuff
statdesc = '\n'.join(['%s : %s' % (key, value) for (key, value) in dic.items()])
plt.text(xmax+.1*(xmax-xmin), 0, statdesc)
Sylvain Page
  • 581
  • 1
  • 7
  • 21
0

In addition to Spandan's answer above, I would suggest to look at the Postprocessing part of the answer here.

The same matplotlib.pyplot.subplots_adjust and matplotlib.pyplot.tight_layout functions can be used with text as well.

talekeDskobeDa
  • 372
  • 2
  • 13