Forums

Can't save matplot plot in directory

Hello, I'm running a file on the console. The command should save an matplot plot as image, but it is not working. There are no errors in the console, but the image is not created. This is the save fig code:

df = df[[eixo_x, eixo_y]] df = df.sort_values(by = 'data')

x_axis = df[eixo_x] y_axis = df[eixo_y] matplotlib.rc('font', size=6) matplotlib.rc('axes', titlesize=8) fig, ax = plt.subplots()

ax.plot(x_axis, y_axis,color=facecolor,linewidth=1,marker='o',markersize=4, markerfacecolor='white' )

ax.xaxis.set_major_locator(ticker.MultipleLocator(1)) fig.autofmt_xdate(rotation=90)

plt.fill_between(x_axis, y_axis, color=facecolor, alpha=0.4)

ax.set_facecolor('#E2E1E2') ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.spines['left'].set_visible(False)

for i in range(len(y_axis)): plt.annotate(str(y_axis[i]), xy=(x_axis[i],y_axis[i]),ha='center', va='bottom',fontsize=5, rotation = 90, xytext = (0,3), textcoords='offset points')

ax.grid(color='white')

fig.autofmt_xdate(rotation=90) plt.rcParams['savefig.facecolor'] = '#E2E1E2'

plt.savefig(graphPath, dpi=300)

(graphPath is 'grafico.png', i tried absolute path, and another directory...same result.). In local machine is working, so i believe that is a simple mistake that i dont understand.

What errors are you getting?

I am having the same problem as @miltonliveira. plt.savefig("filename.png") is not saving my plot. It is working when I run it locally.

You're using a relative file name without paying attention to your working directory. See https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/