matplotlib图例底部的传说

时间:2017-10-24 02:55:28

标签: python django matplotlib

我试图复制一张在AmCharts中完成的图表,但到目前为止我很困惑的方式是让传说在外面和底部的情节

现在我正在使用这个django视图来渲染情节

def my_view(request)
    import matplotlib.pyplot as plt
    import numpy as np
    from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas

    colors = ["#FF9800", "#00E676", "#03A9F4", "#1A237E", "#AD1457", "#F44336", "#1DE9B6", "#01579B", "#CFD8DC",
          "#90A4AE", "#263238", "#B71C1C", "#FFEB3B"]

    data=('serv1','Aplicaiones','serv3','serv4','servi5','serv1','serv2','serv3','serv4','servi5',)
    datos=[99.3,99,23,100,99.3,99,23,100,99.3,99]
    figure=plt.Figure()

    pos=np.arange(len(datos))
    ax = figure.add_subplot(111)

    b=ax.bar(pos, datos,color=colors)

    ax.legend(b,data,loc='upper center', bbox_to_anchor=(0,-.05, 1,0), ncol=5,mode="expand")


    ax.axis('off') #
    response = HttpResponse(content_type='image/png')

    figure.bbox_inches='tight'
    canvas = FigureCanvas(figure)

    canvas.print_png(response)

    return response

参数bbox_to_anchor看起来像是要走的路,但是图表有一个限制,标签的结尾太靠近吧了,我的目标是把标签(每个条1个)留给轴描述的空间

我想要的https://d26dzxoao6i3hh.cloudfront.net/items/2U113d3m0O3Z0o053L3F/Captura%20de%20pantalla%202017-10-23%20a%20la(s)%2023.45.00.png?v=16e23ee7

现在这就是我得到的https://d26dzxoao6i3hh.cloudfront.net/items/0l0v2P2N3h1M15022V43/Captura%20de%20pantalla%202017-10-23%20a%20la(s)%2023.47.05.png?v=a36b97c9

0 个答案:

没有答案