oldoc63 / learningDS

Learning DS with Codecademy and Books
0 stars 0 forks source link

Axis and Labels #478

Open oldoc63 opened 1 year ago

oldoc63 commented 1 year ago

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:

  1. The minimum x-value displayed
  2. The maximum x-value displayed
  3. The minimum y-value displayed
  4. The maximum y-value displayed

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]).

oldoc63 commented 1 year ago
  1. We have plotted a line representing someone's spending on coffee over the past 12 years.
  2. Let modify the axes to zoom in a bit more on our line chart. Use plt.axis() to modify the axes so that the x-axis goes from 0 to 12, and the y-axis goes from 2900 to 3100.
oldoc63 commented 1 year ago

Labeling the Axes

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.

oldoc63 commented 1 year ago

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:

oldoc63 commented 1 year ago
  1. Label the x-axis 'Time'.
  2. Label the y-axis 'Dollars spent on coffee'.
  3. Add the title 'My Last Twelve Years of Coffee Drinking'