Control the number of rows within a legend

后端 未结 1 1583
死守一世寂寞
死守一世寂寞 2021-02-19 02:37

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 re

相关标签:
1条回答
  • 2021-02-19 03:41

    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)
    

    0 讨论(0)
提交回复
热议问题