Pic not downloaded

I want to download the visualization I made in Jupyter Notebook. The picture got downloaded, but it’s a white blank page. Please help me. The following codes were used:
plt.show()
plt.savefig(‘C:\Pathname\top_5_countries_cases.png’, dpi=200, bbox_inches=‘tight’)

On Windows you have to give paths using raw strings, e.g. prefix them with r.
Like that:

plt.savefig(r'C:\Pathname\top_5_countries_cases.png', dpi=200, bbox_inches=‘tight’)

It is necessary because \ used in Windows paths is also an escape character. Such a character makes Python interpret the character next to \ in a special way. And you have a bad luck, because "\t" means Tab character not slash and ‘t’.

Hi there, thank you for the reply. However, it’s still not working. Could you please take a look at my whole code? I wanted to draw horizontal bar graph.

top_5_countries = cases.groupby(‘Country’)[‘Count_median’].sum().nlargest(5)
colors = [‘skyblue’, ‘lightgreen’, ‘salmon’, ‘orange’, ‘lightblue’]
plt.figure(figsize=(10, 6))
bars = top_5_countries.plot(kind=‘barh’, color=colors)
plt.xlabel(‘Total Number of Cases’)
plt.ylabel(‘Country’)
plt.title(‘Top 5 Countries with the Highest Number of Cases’)
plt.gca().invert_yaxis()
for bar, count in zip(bars.patches, top_5_countries.values):
plt.text(bar.get_width() + 0.1, bar.get_y() + bar.get_height()/2 - 0.1, f’{count:,}', va=‘center’)
plt.show()

Then in next line i did this,
plt.savefig(r’C:\Pathname\top_5_countries_cases.png’, dpi=200, bbox_inches=‘tight’)

Result is <Figure size 640x480 with 0 Axes>. But it shows again a white black page…

Please paste again your code, but this time fenced between ``` just like the pined thread says. You don’t have to make new post, just edit your last post. I’m writing that because your code was mangled by the forum software.

Remember that if some of us wish to help you, then he/she has to be able to copy your code and try run it.

1 Like