⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 legend_auto.py

📁 非原创。很好的python例子
💻 PY
字号:
"""This file was written to test matplotlib's autolegend placementalgorithm, but shows lots of different ways to create legends so isuseful as a general examplesThanks to John Gill and Phil ?? for help at the matplotlib sprint atpycon 2005 where the auto-legend support was written."""from pylab import *import sysN = 100x = arange(N)def fig_1():    figure(1)    t = arange(0, 40.0 * pi, 0.1)    l, = plot(t, 100*sin(t), 'r', label='sine')    legend(loc='best')def fig_2():    figure(2)    plot(x, 'o', label='x=y')    legend(loc='best')def fig_3():    figure(3)    plot(x, -x, 'o', label='x= -y')    legend(loc='best')def fig_4():    figure(4)    plot(x, ones(len(x)), 'o', label='y=1')    plot(x, -ones(len(x)), 'o', label='y=-1')    legend(loc='best')def fig_5():    figure(5)    n, bins, patches = hist(randn(1000), 40, normed=1)    l, = plot(bins, normpdf(bins, 0.0, 1.0), 'r--', label='fit', linewidth=3)    legend([l, patches[0]], ['fit', 'hist'], loc='best')def fig_6():    figure(6)    plot(x, 50-x, 'o', label='y=1')    plot(x, x-50, 'o', label='y=-1')    legend(loc='best')def fig_7():    figure(7)    xx = x - (N/2.0)    plot(xx, (xx*xx)-1225, 'bo', label='$y=x^2$')    plot(xx, 25*xx, 'go', label='$y=25x$')    plot(xx, -25*xx, 'mo', label='$y=-25x$')    legend(loc='best')def fig_8():    figure(8)    b1 = bar(x, x, color='m')    b2 = bar(x, x[::-1], color='g')    legend([b1[0], b2[0]], ['up', 'down'], loc='best')def fig_9():    figure(9)    b1 = bar(x, -x)    b2 = bar(x, -x[::-1], color='r')    legend([b1[0], b2[0]], ['down', 'up'], loc='best')def fig_10():    figure(10)    b1 = bar(x, x, bottom=-100, color='m')    b2 = bar(x, x[::-1], bottom=-100, color='g')    b3 = bar(x, -x, bottom=100)    b4 = bar(x, -x[::-1], bottom=100, color='r')    legend([b1[0], b2[0], b3[0], b4[0]], ['bottom right', 'bottom left',                                          'top left', 'top right'],           loc='best')if __name__ == '__main__':    nfigs = 10    figures = [int(f) for f in sys.argv[1:]]    if len(figures) == 0:        figures = range(1, nfigs+1)    for fig in figures:        fn_name = "fig_%d" % fig        fn = globals()[fn_name]        fn()            show()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -