1

this is my code:

hours = [hour1, hour2, hour3, hour4, hour5]
    water_intake = [litres_of_water_consumed1, litres_of_water_consumed2, litres_of_water_consumed3, litres_of_water_consumed4, litres_of_water_consumed5]
    plt.plot(hours, water_intake)
    plt.title('Your water intake')
    plt.xlabel('hours')
    plt.ylabel('litres of water consumed')

But instead of using plot.show() and then saving the plot image through matplotlib window I want to do it through the script is there anyway to do that?

0

2 Answers 2

1

you can use plt.savefig() for saving matplot figures.

Sign up to request clarification or add additional context in comments.

Comments

1

You can get an image from a matplotlib plot as a numpy array image, if needed:

ax.axis('off')
fig.tight_layout(pad=0)

# To remove the huge white borders
ax.margins(0)

fig.canvas.draw()
image_from_plot = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
image_from_plot = image_from_plot.reshape(fig.canvas.get_width_height()[::-1] + (3,))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.