Please assist to export a bar graph as png or jpg, see the screenshot attached and code in dialog box

hello everyone

Please assist me to export the bar graph as png of jpg, as produce the the code below.

df.set_index(‘CLASS’).plot(
kind=‘bar’,
figsize=(10,4), # Figsize to make the plot larger
#title=‘’, # Adding a title to the top
xlabel=“Land use classes”, # Adding a label on the xaxis
ylabel=“Area”, # Adding a label on y axis
fontsize=‘large’); # Making my ticks a bit bigger)

dff.set_index(‘CLASS’).plot(
kind=‘barh’,
figsize=(10,4), # Figsize to make the plot larger
#title=‘My SF Bar Plot’, # Adding a title to the top
xlabel=“Land use classes”, # Adding a label on the xaxis
ylabel=“Area (%)”, # Adding a label on y axis
fontsize=‘large’); # Making my ticks a bit bigger)

Assuming you are using matplotlib as the backend for the pandas plotting, you can use df.set_index('CLASS').plot(...).get_figure().savefig('myplot.png'). Check matplotlib docs for more details.

1 Like