I am currently trying to plot a large amount of data on a single plot. I have structured my representation using repeated colors and symbols. However, when plotting the final results, the legend appears slightly off because I cannot control the number of rows within it. Thus, instead of getting 5 repeated green, then 5 repeated red, 5 repeated blue then 2 other, I get 5 -4 -4 -4 (where I would have prefered 5 - 5 - 5 - 2)
You can clearly see this in attached image.
Right now I use these options for the legend:
axp.legend(loc="lower right",ncol=4)
legend handle. The original object which is used to generate an appropriate entry in the legend.
To change the legend size of the plot, the user needs to use the cex argument of the legend function and specify its value with the user requirement, the values of cex greater than 1 will increase the legend size in the plot and the value of cex less than 1 will decrease the size of the legend in the plot.
The legend on an Excel scatter plot is simply a list of the names for each of the series on the chart. The legend is color coordinated, so you can quickly determine which data points belong to which name.
I also had this problem a couple of times and use this workaround by adding dummy items to the legend to fill the last column, if there are more elegant methods available I would also be very interested to hear about them.
import numpy as np
import matplotlib.pylab as pl
pl.figure()
pl.plot(np.arange(10), np.random.random([10,5]), color='r', label='red')
pl.plot(np.arange(10), np.random.random([10,5]), color='g', label='green')
pl.plot(np.arange(10), np.random.random([10,5]), color='b', label='blue')
pl.plot(np.arange(10), np.random.random([10,2]), color='k', label='black')
# Add empty dummy legend items
pl.plot(np.zeros(1), np.zeros([1,3]), color='w', alpha=0, label=' ')
pl.legend(ncol=4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With