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?

ash2021
  • 63
  • 5

2 Answers2

1

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

demetere._
  • 268
  • 2
  • 10
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,))
user942761
  • 38
  • 4