Here is the explanation of the code:
- plt.hist(nd) plots the histogram with randomly generated nd data.
- plt.ylabel('histogram') labels the y axis as histogram.
- file_ext is the list of all supported file formats.
- The for loop displays the format being saved for all formats.
- plt.savefig() saves the figure with the name Histogram.file_ext such as Histogram.png, Histogram.pdf, and so on.
- plt.savefig() is similar to plt.show() that displays the figure on the screen, whereas plt.savefig() sends the figure to the working directory in the specified format.
You can use both the methods in the same session, as we have done here, so that it saves the file in the specified format to the working directory and also displays it on your ...