Open oldoc63 opened 1 year ago
Eventually, we will want to show these plots to other people to convince them of important trends in our data. When we do that, we'll want to make our plots look as professional as possible. The first step towards a professional-looking plot is adding labels to the x-axis and y-axis, and giving the plot a title. We can label the x and y axes by using plt.xlabel() and plt.ylabel(). The plot title can be set by using plt.title(). All of these commands require a string, which is a set of characters in either single or double quotes.
For example, if someone has been keeping track of their happiness (on a scale out of 10) throughout the day and wants to display this information with labeled axes, we can use the following commands:
Sometimes, it can be helpful to zoom in or out of the plot, especially if there is some detail we want to address. To zoom, we can use plt.axis(). We use plt.axis() by feeding it a list as input. This list should contain:
For example, if we want to display a plot from x=0 to x=3 and from y=2 to y=5, we would call plt.axis([0,3,2,5]).