0

I saw quite a few different approaches to plot in flask app with matplotlib.

My question is now, why does my plot not appear.

@blueprint.route('/plot')
def plot():
    left = [1, 2, 3, 4, 5]
    # heights of bars
    height = [10, 24, 36, 40, 5]
    # labels for bars
    tick_label = ['one', 'two', 'three', 'four', 'five']
    # plotting a bar chart
    plt.bar(left, height, tick_label=tick_label, width=0.8, color=['red', 'green'])
    # naming the y-axis
    plt.ylabel('y - axis')
    # naming the x-axis
    plt.xlabel('x - axis')
    # plot title
    plt.title('My bar chart!')

    plt.savefig('apps/static/images/assets/plot.png')

    return render_template('tables.html', url='apps/static/images/assets/plot.png')
<body>
<div>
<img src={{url}} alt="Chart" height="auto" width="100%">
    </div>
</body>

Thank you in Advance

  • There's no real need to create a file on disk, you can create it and send it from memory (RAM), see https://stackoverflow.com/a/73797701/2836621 – Mark Setchell Jan 10 '23 at 14:04

0 Answers0