0

I am using matplotlib as follows:

import matplotlib.pyplot as plt
import matplotlib.dates as mdates


# Graph Size
plt.figure(figsize=(20, 12))
# Axis X
plt.xlabel('name 1', fontsize=font_size_graph)
# Axis Y
plt.ylabel('name 2', fontsize=font_size_graph)

# Colors
colors=pltcolor(name)  
# Text
plt.text(80, 3.1, 'name 3', color='#F6B002', fontsize=font_size_graph)
plt.text(80, 1.8, 'name 4', color='#FF4431', fontsize=font_size_graph)

# Grid
axes = plt.gca()
axes.spines['right'].set_visible(False)
axes.spines['top'].set_visible(False)
plt.grid(color='#DCDCDC', linestyle='-', linewidth=1)

################################
##            SAVE            ##
################################ 
#Save plot as PNG & copy it to DataLake Store
plt.savefig('path' + '.png', bbox_inches = 'tight')

and I got the following error:

matpotlib Image size of 1092843x1004 pixels is too large. It must be less than 2^16 in each direction Any idea which setting to change to fix this error

scalacode
  • 1,096
  • 1
  • 16
  • 38
  • You forgot to define `pltcolor(name)`. What is this? The gigantic size often happens when using e.g. timestamps for the coordinates and `plt.text(x,y,...)` at a very far away position (compared to the data coordinates used on the axes). – JohanC Jan 27 '22 at 16:29
  • See e.g. https://stackoverflow.com/questions/52375207/matplotlib-error-image-size-of-362976x273-pixels-is-too-large – JohanC Jan 27 '22 at 16:29
  • 1
    @JohanC is correct. Text doesn’t change the limits of your axes so they go from 0-1. You put text at 80 which is way off the page. Then you call bbox_inches=tight which resize the page to include the text. Try axes.set_xlim(0,100) and you should be fien – Jody Klymak Jan 27 '22 at 17:53
  • @Jody Klymak axes.set_xlim(0,100)worked flawlessly , thanks a lot – scalacode Jan 28 '22 at 09:16

0 Answers0