When we're making lots of plots, it's easy to end up with lines that have been plotted and not displayed. If we're not careful, these forgotten lines will show up in your new plots. In order to be sure that you don't have any stray lines, you can use the command plt.close('all') to clear all existing plots before you plot a new one.
Previously, we put two set of axes into the same figure. Sometimes, we would rather have two separate figures. We can use the command plt.figure() to create new figures and size them how we want. We can add the keyword figsize=(width, height) to set the size of the figure, in inches. We use parentheses ((and)) to pass in the width and height, which are separated by a comma(,).
To create a figure with a width of 4 inches, and height of 10 inches: plt.figure(figsize=(4,10))
Once we've created a figure, we may want to save it so that we can use it in a presentation or a web site. We can use the command plt.savefig() to save out to many different file formats, such as png, svg or pdf. After plotting, we can call plt.savefig('name_of_graph.png'):
We created a figure out of the plot word_lenght against years.
On the next line, create a figure with 7 inches of width and 3 inches of height and plot power generated against years. Save a figure in a file called 'power_generated.png'.
When we're making lots of plots, it's easy to end up with lines that have been plotted and not displayed. If we're not careful, these forgotten lines will show up in your new plots. In order to be sure that you don't have any stray lines, you can use the command plt.close('all') to clear all existing plots before you plot a new one.
Previously, we put two set of axes into the same figure. Sometimes, we would rather have two separate figures. We can use the command plt.figure() to create new figures and size them how we want. We can add the keyword figsize=(width, height) to set the size of the figure, in inches. We use parentheses ((and)) to pass in the width and height, which are separated by a comma(,).
To create a figure with a width of 4 inches, and height of 10 inches:
plt.figure(figsize=(4,10))
Once we've created a figure, we may want to save it so that we can use it in a presentation or a web site. We can use the command plt.savefig() to save out to many different file formats, such as png, svg or pdf. After plotting, we can call plt.savefig('name_of_graph.png'):