0

Im trying to replicate a chart the was done in AmCharts but so far Im confused in the way to make the legend be outside and at the bottom of the plot

right now im using this django view to render the plot

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

the parameter bbox_to_anchor looks like the way to go, but chart has a limit and the label ends too close to the bars, my goal is to put the label (1 for each bar) leave space for axis description

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

right now this is what I got https://d26dzxoao6i3hh.cloudfront.net/items/0l0v2P2N3h1M15022V43/Captura%20de%20pantalla%202017-10-23%20a%20la(s)%2023.47.05.png?v=a36b97c9

Freaktor
  • 700
  • 1
  • 10
  • 21
  • Have you looked at this answer by Joe Kington? https://stackoverflow.com/questions/4700614/how-to-put-the-legend-out-of-the-plot/4701285?s=1|203.5537#4701285 Last example has the legend separately at the bottom. I think what you also need to do is shrink your plot a bit with ax.set_position(). – Paul Oct 24 '17 at 03:20
  • looks like my searching skils had faded with the time. thanks for pointing out the solution. – Freaktor Oct 24 '17 at 13:27

0 Answers0