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

Зміст курсу

Ultimate Visualization with Python

Customizing GridCustomizing Grid

Another important part of the customization is grid customization. pyplot module has a grid() function for this purpose.

Visibility and Axes

Its first parameter visible specifies whether to show the grid lines (by default, they are not shown).

axis parameter specifies whether to apply the customization to the grid lines parallel to the x-axis (set to 'y'), to the y-axis (set to 'x') or both of them (set to 'both'), which is the default value. Let’s clarify all of this with an example:

In this example we set visible to True, however, since we also set axis='x', it only applies to the grid lines parallel to the y-axis. Hence why there are only vertical grid lines shown, which makes the plot more detailed, yet it is not cluttered with perpendicular grid lines, which are not necessary here.

Color and Transparency

It is also possible to change the color of the grid lines using the color parameter and their transparency using the alpha parameter. Both of these parameters are already familiar to us, so let’s see them in action:

Now our grid lines are black (color='black') and are more transparent (alpha=0.2) which makes the plot look even better.

There are still more possible parameters for the grid() functions (they are not used so often), so here is its documentation in case you want to explore more.

Завдання

  1. Use the appropriate function to customize the grid lines.
  2. Make the grid lines visible via correctly specifying the leftmost argument.
  3. Apply the customization only to the grid lines parallel to the x-axis via specifying the second parameter.
  4. Set the color of the grid lines to 'slategrey' via specifying the third parameter.
  5. Set the transparency of the grid lines to 0.5 via specifying the rightmost parameter.

Все було зрозуміло?

Секція 3. Розділ 5
toggle bottom row
course content

Зміст курсу

Ultimate Visualization with Python

Customizing GridCustomizing Grid

Another important part of the customization is grid customization. pyplot module has a grid() function for this purpose.

Visibility and Axes

Its first parameter visible specifies whether to show the grid lines (by default, they are not shown).

axis parameter specifies whether to apply the customization to the grid lines parallel to the x-axis (set to 'y'), to the y-axis (set to 'x') or both of them (set to 'both'), which is the default value. Let’s clarify all of this with an example:

In this example we set visible to True, however, since we also set axis='x', it only applies to the grid lines parallel to the y-axis. Hence why there are only vertical grid lines shown, which makes the plot more detailed, yet it is not cluttered with perpendicular grid lines, which are not necessary here.

Color and Transparency

It is also possible to change the color of the grid lines using the color parameter and their transparency using the alpha parameter. Both of these parameters are already familiar to us, so let’s see them in action:

Now our grid lines are black (color='black') and are more transparent (alpha=0.2) which makes the plot look even better.

There are still more possible parameters for the grid() functions (they are not used so often), so here is its documentation in case you want to explore more.

Завдання

  1. Use the appropriate function to customize the grid lines.
  2. Make the grid lines visible via correctly specifying the leftmost argument.
  3. Apply the customization only to the grid lines parallel to the x-axis via specifying the second parameter.
  4. Set the color of the grid lines to 'slategrey' via specifying the third parameter.
  5. Set the transparency of the grid lines to 0.5 via specifying the rightmost parameter.

Все було зрозуміло?

Секція 3. Розділ 5
toggle bottom row
some-alt