Dynamically add legends to matplotlib plots in python

丶灬走出姿态 提交于 2019-12-05 05:07:34

I can't reproduce your problem. With a few adjustments to your script, what you're expecting is working for me.

import matplotlib.pylab
import numpy as np

for q in range(1,10):
    # create a random, 100 length array
    s_A_approx = np.random.randint(0, 100, 100)
    # note I had to make q a string to avoid an AttributeError when 
    # initializing the legend
    matplotlib.pylab.plot(s_A_approx, marker='.', linestyle='None', label=str(q))

matplotlib.pylab.legend(loc='upper left')
matplotlib.pylab.show()


If it helps, here's my matplotlib version:

>>> import matplotlib
>>> matplotlib.__version__
'1.0.1'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!