oldoc63 / learningDS

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

Modify Ticks #481

Open oldoc63 opened 1 year ago

oldoc63 commented 1 year ago

In all of our previous exercises, our commands have started with plt.. In order to modify tick marks, we'll have to try something a little bit different. Because our plots can have multiple subplots, we have to specify which one we want to modify, In order to do that, we call plt.subplot() in a different way: ax = plt.subplot(1,1,1)

ax is an axes object, and it lets us modify the axes belonging to a specific subplot. Even if we only have one subplot, when we want to modify the ticks, we will need to start by calling either ax = plt.subplot(1,1,1) or ax = plt.subplot() in order to get our axes object.

Suppose we wanted to set our x-ticks to be at 1, 2 and 4.

oldoc63 commented 1 year ago

We can also modify the y-ticks by using ax.set_yticks().

When we change the x-ticks, their labels automatically change to match. But, if we want special labels (such as strings), we can use the command ax.set_xticklabels() or ax.set_yticklabels(). For example, we might want to have a y-axis with ticks at 0.1, 0.6, and 0.8, but label them 10%, 60% and 80%, respectively.

oldoc63 commented 1 year ago
  1. Let's imagine we are working for a company called Dinnersaur, that delivers dinners to people who don't want to cook. Dinnersaur recently started a new service that is subscription-based, where users sign up for a whole year of meals, instead of buying meals on-demand. We have plotted a line representing the proportion of users who have switched over to this new service since it was rolled out in January. First, save the set of axes in a variable called ax. We will use ax to set the x- and y-ticks and labels to make this graph easier to read.
oldoc63 commented 1 year ago
  1. Using ax, set the x-ticks to be the months list.
  2. Set the x-tick labels to be the month_names list.
oldoc63 commented 1 year ago
  1. Set the y-ticks to be [0.10, 0.25, 0.5, 0.75].
oldoc63 commented 1 year ago
  1. Label the y-ticks to be the percentages that correspond to the values [0.10, 0.25, 0.5, 0.75], instead of decimals.