Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Axes Customization | Plots Customization
course content

Contenido del Curso

Ultimate Visualization with Python

Axes CustomizationAxes Customization

Ticks Customization

For adjusting ticks, the pyplot module has two functions with identical syntax:

  • xticks() for the x-axis;
  • yticks() for the y-axis.

Both functions have two most important parameters:

  • ticks specifies where you want the ticks to appear (use an array-like type). You can remove ticks by passing an empty list;
  • labels assigns labels to the ticks at their specified locations. This parameter must be used alongside the ticks parameter.

You can also provide additional keyword arguments to control the appearance of the labels.

Now it’s time for some examples. Here is one of the graphs we have recently created:

Plot with default ticks

Everything seems to be pretty fine with this plot, however, it would be better to have more years on the x-axis in this range (1995-2020). Let’s use xticks() for this purpose:

Now there is every second year in this range on the x-axis. We accomplished this using the range() function (with the step parameter 2) for the ticks argument.

Moreover, we used a keyword argument rotation to rotate the ticks labels 30 degrees counterclockwise for better readability.

We could also specify the list of labels for the ticks via setting the labels (e.g, labels = ['label1', 'label2']).

Axes Labels Customization

You can use xlabel() and ylabel() functions from the pyplot module to set the labels for the x-axis and y-axis. These functions require only one parameter: the label itself (a string).

It is also possible to modify the label apperance, for instance, set the font size via fontsize keyword argument or its color via color keyword argument.

In addition, there is loc parameter which specifies the label location (center by default).

  • For x-axis label 'left', 'center' and 'right' are possible values;
  • For y-axis instead of 'left' and 'right' there is 'top' and 'bottom'.

You can explore more in the documentation: xlabel, ylabel.

Tarea

  1. Use the correct function to set data_linear as x-axis ticks.
  2. Use the correct function to set 'x' as the x-axis label.
  3. Use 'right' as the location for the x-axis label.
  4. Use the correct function to set 'y' as the y-axis label.
  5. Use 'top' as the location for the y-axis label.
  6. Set rotation parameter to 0 for the y-axis label.

¿Todo estuvo claro?

Sección 3. Capítulo 3
toggle bottom row
course content

Contenido del Curso

Ultimate Visualization with Python

Axes CustomizationAxes Customization

Ticks Customization

For adjusting ticks, the pyplot module has two functions with identical syntax:

  • xticks() for the x-axis;
  • yticks() for the y-axis.

Both functions have two most important parameters:

  • ticks specifies where you want the ticks to appear (use an array-like type). You can remove ticks by passing an empty list;
  • labels assigns labels to the ticks at their specified locations. This parameter must be used alongside the ticks parameter.

You can also provide additional keyword arguments to control the appearance of the labels.

Now it’s time for some examples. Here is one of the graphs we have recently created:

Plot with default ticks

Everything seems to be pretty fine with this plot, however, it would be better to have more years on the x-axis in this range (1995-2020). Let’s use xticks() for this purpose:

Now there is every second year in this range on the x-axis. We accomplished this using the range() function (with the step parameter 2) for the ticks argument.

Moreover, we used a keyword argument rotation to rotate the ticks labels 30 degrees counterclockwise for better readability.

We could also specify the list of labels for the ticks via setting the labels (e.g, labels = ['label1', 'label2']).

Axes Labels Customization

You can use xlabel() and ylabel() functions from the pyplot module to set the labels for the x-axis and y-axis. These functions require only one parameter: the label itself (a string).

It is also possible to modify the label apperance, for instance, set the font size via fontsize keyword argument or its color via color keyword argument.

In addition, there is loc parameter which specifies the label location (center by default).

  • For x-axis label 'left', 'center' and 'right' are possible values;
  • For y-axis instead of 'left' and 'right' there is 'top' and 'bottom'.

You can explore more in the documentation: xlabel, ylabel.

Tarea

  1. Use the correct function to set data_linear as x-axis ticks.
  2. Use the correct function to set 'x' as the x-axis label.
  3. Use 'right' as the location for the x-axis label.
  4. Use the correct function to set 'y' as the y-axis label.
  5. Use 'top' as the location for the y-axis label.
  6. Set rotation parameter to 0 for the y-axis label.

¿Todo estuvo claro?

Sección 3. Capítulo 3
toggle bottom row
some-alt