I was having a difficult time fixing the display of a legend in one matplotlib figure, and then I noticed that maybe there is an incongruence in matplotlib documentation, or I am not searching in the right place.
In my code, I can only make a horizontal legend work if I define ncol, as in the following example from matplotlib demo:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 1)
# Plot the lines y=x**n for n=1..4.
ax = plt.subplot(2, 1, 1)
for n in range(1, 5):
plt.plot(x, x**n, label="n={0}".format(n))
plt.legend(loc="upper left", bbox_to_anchor=[0, 1],
ncol=2, shadow=True, title="Legend", fancybox=True)
ax.get_legend().get_title().set_color("red")
However, also in matplotlib documentation, they state that ncols(and not ncol) is the right parameter name.
I also tested with alignment parameter and I got the same error as if I use ncols: __init__() got an unexpected keyword argument 'alignment'.
I'm not sure if this is an error or I am missing something here. I'm using matplotlib 3.4.3.
