Adding a grid

While a blank plot background is clean, sometimes we may like to get some reference gridlines for better reference, such as in the multiline case.

We can turn on the background gridlines by calling plt.grid(True) before plt.show(). For example, we can add this command to the preceding multi-city temperature plot to obtain the following plot:

Similarly, when we do not want the grid any longer, such as when using styles with gridlines as the default, we can use  plt.grid(False) to remove the grid.

Detailed styling options will be discussed in the next chapter. The grid in the preceding example distinctly stands out too much and interferes with the interpretation of the line plots. Grid line properties, such as line width, color, and dash patterns, are adjustable within the plt.grid() command; here is a brief example of making the grid more subtle:

plt.grid(True,linewidth=0.5,color='#aaaaaa',linestyle='-')

As seen in the following plot, the grid lines become lighter and less interfering with the data lines in comparison to the default grid color in the plot in the last example:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.200.28