1

I would like to add a description box in matplotlib, similar to what is shown in the picture. I have hidden sensitive details in the description box since it cannot be made public

Is there a way to add such a description box next to the plots (ofcourse without hiding the details) ?

Description of intented plot

I have tried to search on the internet, but all I get is how to add description within the plot, and not like how I would like it to be

Can anyone help me with this ?

Masoom Kumar
  • 129
  • 1
  • 8
  • This question has already beeen answered here: [enter link description here](https://stackoverflow.com/questions/4700614/how-to-put-the-legend-out-of-the-plot) – lakedue Apr 16 '21 at 10:28

1 Answers1

5

You could use matplotlib.pyplot.text.

If you specify transform=ax.transAxes, so that the coordinates are relative to the axes bounding box, and verticalalignment='top', you can get something very similar to the picture you posted.

import numpy as np
import matplotlib.pyplot as plt

x_val = np.random.uniform(low=-4, high=4, size=200)

fig, ax = plt.subplots()
ax.hist(x_val,bins=20)

textbox = '\n'.join([
    'Evaluation flow name: ',
    'Evaluation description: ',
    '',
    'Evaluation flow SVN Revision: ',
    'Dataset path: ',
    'Dataset name: ',
    '',
    'Filter: ',
    'Grouping: ',
    'Files selected with filter and grouping: ',
    'Files with all needed signals: ',
    '',
    '...',
    '...',
    '...',
])

bbox = dict(boxstyle='square', facecolor='lavender', alpha=0.5)
fig.text(1.1,1,textbox,fontsize=10,transform=ax.transAxes, bbox=bbox, 
verticalalignment='top')

which gives the following output: https://i.stack.imgur.com/57rnI.png

For the text I used a join() just to have something easier to read and modify (with respect to a single long string full of '\n', perhaps there are better ways to do that.

Dharman
  • 30,962
  • 25
  • 85
  • 135
riclol
  • 66
  • 3