Wrapping Plot Caption

Viewed 56

I'm trying to wrap the caption for my (very simple) plot. This is my code for the caption so far:

t = "Figure 1: This caption is too long to be displayed over one line, in fact it will have to be spread over multiple lines. The whole plot is described in this caption so it goes on and on forever."

plt.figtext(0.1, -0.3, t, wrap = True, horizontalalignment = 'left', fontsize = 12, style = 'italic')

And these are the libraries I have imported:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

I thought the wrap = True in plt.figtext would sort out the line wrapping, but it doesn't. Instead, my caption goes continues on one line and doesn't wrap. I'm using a Jupyter notebook.

I'm sure there is a simple way to fix this, I have just not been able to figure it out.

Thanks for your help!

1 Answers

Wrap does not work in Jupyter notebook:

Wrapping does not work together with savefig(..., bbox_inches='tight') (which is also used internally by %matplotlib inline in IPython/Jupyter). The 'tight' setting rescales the canvas to accommodate all content and happens before wrapping.

Checkout wrap documentation.

Related