0

I have been trying to make my plot size constant, but when i do either the image saved to excel and directory is complete blank or the plot is missing in the image with x-ticks and y-ticks. the code i have been using is below:

yAxis = list(modelingData[column])
imageName = str(column)+'.png'
columnText = 'B'
columnText += str(columnValue)
# creates a seperate plots for every timestamp vs column and saves it
fig,ax=plt.subplots()
ax.plot(xAxis,yAxis, linestyle='-', marker='o')
# size of plot horizontally fixed to 5 inches and height to 10 inches
            
# rotating the x axis labels
plt.setp(ax.get_xticklabels(), rotation=30, horizontalalignment='right', fontsize='x-small')
# plt.figure(figsize=(7, 5))
# plt.xticks(rotation = 45)
plt.title('Timestamp vs '+str(column))
plt.xlabel('Timestamp')
plt.ylabel(str(column))

plt.savefig(os.path.join(directoryToDumpData,imageName), bbox_inches='tight', dpi=100) 
plt.close()

img = openpyxl.drawing.image.Image(os.path.join(directoryToDumpData,imageName))  
img.anchor = columnText
plotSheet.add_image(img)
           
columnValue+=20 

any help would be appreciated. Also I'm a beginner in this so please help out

  • You need to change `plt.subplots()` to `plt.subplots(figsize=(7, 5))`. Both the functions `plt.subplots()` and `plt.figure()` create a **new** figure. – JohanC Mar 09 '22 at 07:24

0 Answers0