9951 explained code solutions for 126 technologies


python-matplotlibHow to put labels horizontally in legend


import matplotlib.pyplot as plt
plt.plot([1,2,10,6,15,3,4], label='A')
plt.plot([4,2,11,2,1,20,25], label='B')
plt.legend(ncol=2)
plt.show()ctrl + c
import matplotlib.pyplot as plt

loads Matplotlib module to use plotting capabilities

.plot(

plot specified data

label

set label for this line

.legend(

show and configure legend

ncol

configure number of columns to place labels into (we use 2 because we have 2 labels)

.show()

render chart in a separate window