I’m working with a Jupyter Notebook running on a browser with Windows OS. I’m trying to save a bar plot using Matplotlib, but I keep encountering an OSError: [Errno 28] Invalid argument error. Here is the code I’m using:
import matplotlib.pyplot as plt
# Given values
x = [5, 2, 3, 7, 23, 43, 30, 16, 4, 3]
y = [20, 30, 40, 50, 60, 65, 70, 80, 90, 100]
# Create the bar plot
plt.bar(range(len(x)), x, tick_label=y)
# Add labels and title
plt.xlabel('Number of Images')
plt.ylabel('Number of Person')
plt.title('Bar Plot Example')
# Save the plot
plt.savefig('bar_plot_valid.png')
# Display the plot
plt.show()
Error:
When I run the above code, I get the following error:
OSError: [Errno 28] Invalid argument: 'bar_plot_valid.png'
Additional Context:
I am running Jupyter Notebook in a web browser on a Windows operating system.
I have checked and ensured that the directory is writable.
The plot displays correctly using plt.show(), but the error occurs when trying to save it using plt.savefig().
What I’ve Tried:
- Changing the filename to a different name.
- Using an absolute path instead of a relative path.
- Checking for any file system restrictions.
Question:
What could be causing this OSError: [Errno 28] Invalid argument error when trying to save a plot, and how can I resolve it?
3