Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Adding Title to the Plot | Plots Customization
Ultimate Visualization with Python
course content

Conteúdo do Curso

Ultimate Visualization with Python

Ultimate Visualization with Python

1. Matplotlib Introduction
2. Creating Commonly Used Plots
3. Plots Customization
4. More Statistical Plots
5. Plotting with Seaborn

Adding Title to the Plot

Choosing a Title

First of all, a good plot should have a concise yet meaningful title. Titles, such as "Line plot" or "Scatter plot" are too abstract and give us no insight about the purpose of the plot or its data. An example of a good title is "New York Average Monthly Temperatures (2022)", since we understand what the data is, the place and time period to which our data is related (these aspects are important in our example).

Now let’s have a look how we can set a plot title in matplotlib:

1234567
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] plt.bar(programming_languages, shares, color=['b', 'green', 'red', 'yellow']) # Setting the plot title plt.title('Percentage of users of programming languages') plt.show()
copy

Setting a Title

In order to set a title, we simply use the plt.title() function passing a title as a string. However, there is actually more to it. In addition to the first parameter label, we can modify the font size via the fontsize parameter (10 is a default value) and font color via color (there are more options to font customization, but these two are the most important).

Another important parameter is loc (location) which can take either of the values: center (default), left and right.

Let’s now modify the title in our example:

12345678
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] plt.bar(programming_languages, shares, color=['b', 'green', 'red', 'yellow']) # Customizing the title appearance plt.title('Percentage of users of programming languages', loc='left', fontsize=15, color='indigo') plt.show()
copy

Here we placed the title on the left, made the font larger and changed the font color. Most of the time you will only care about these parameters, however, you can always refer to the documentation for more information.

Tarefa

The code in this task creates a line plot for the average Boston and Seattle yearly temperatures. Your task is the following:

  1. Use the correct function to set the title for the plot.
  2. Set the following title: 'Boston and Seattle average yearly temperatures'.
  3. Set the font size of the title to be 15.
  4. Set the location of the title to right.

Tarefa

The code in this task creates a line plot for the average Boston and Seattle yearly temperatures. Your task is the following:

  1. Use the correct function to set the title for the plot.
  2. Set the following title: 'Boston and Seattle average yearly temperatures'.
  3. Set the font size of the title to be 15.
  4. Set the location of the title to right.

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Seção 3. Capítulo 1
toggle bottom row

Adding Title to the Plot

Choosing a Title

First of all, a good plot should have a concise yet meaningful title. Titles, such as "Line plot" or "Scatter plot" are too abstract and give us no insight about the purpose of the plot or its data. An example of a good title is "New York Average Monthly Temperatures (2022)", since we understand what the data is, the place and time period to which our data is related (these aspects are important in our example).

Now let’s have a look how we can set a plot title in matplotlib:

1234567
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] plt.bar(programming_languages, shares, color=['b', 'green', 'red', 'yellow']) # Setting the plot title plt.title('Percentage of users of programming languages') plt.show()
copy

Setting a Title

In order to set a title, we simply use the plt.title() function passing a title as a string. However, there is actually more to it. In addition to the first parameter label, we can modify the font size via the fontsize parameter (10 is a default value) and font color via color (there are more options to font customization, but these two are the most important).

Another important parameter is loc (location) which can take either of the values: center (default), left and right.

Let’s now modify the title in our example:

12345678
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] plt.bar(programming_languages, shares, color=['b', 'green', 'red', 'yellow']) # Customizing the title appearance plt.title('Percentage of users of programming languages', loc='left', fontsize=15, color='indigo') plt.show()
copy

Here we placed the title on the left, made the font larger and changed the font color. Most of the time you will only care about these parameters, however, you can always refer to the documentation for more information.

Tarefa

The code in this task creates a line plot for the average Boston and Seattle yearly temperatures. Your task is the following:

  1. Use the correct function to set the title for the plot.
  2. Set the following title: 'Boston and Seattle average yearly temperatures'.
  3. Set the font size of the title to be 15.
  4. Set the location of the title to right.

Tarefa

The code in this task creates a line plot for the average Boston and Seattle yearly temperatures. Your task is the following:

  1. Use the correct function to set the title for the plot.
  2. Set the following title: 'Boston and Seattle average yearly temperatures'.
  3. Set the font size of the title to be 15.
  4. Set the location of the title to right.

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Seção 3. Capítulo 1
toggle bottom row

Adding Title to the Plot

Choosing a Title

First of all, a good plot should have a concise yet meaningful title. Titles, such as "Line plot" or "Scatter plot" are too abstract and give us no insight about the purpose of the plot or its data. An example of a good title is "New York Average Monthly Temperatures (2022)", since we understand what the data is, the place and time period to which our data is related (these aspects are important in our example).

Now let’s have a look how we can set a plot title in matplotlib:

1234567
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] plt.bar(programming_languages, shares, color=['b', 'green', 'red', 'yellow']) # Setting the plot title plt.title('Percentage of users of programming languages') plt.show()
copy

Setting a Title

In order to set a title, we simply use the plt.title() function passing a title as a string. However, there is actually more to it. In addition to the first parameter label, we can modify the font size via the fontsize parameter (10 is a default value) and font color via color (there are more options to font customization, but these two are the most important).

Another important parameter is loc (location) which can take either of the values: center (default), left and right.

Let’s now modify the title in our example:

12345678
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] plt.bar(programming_languages, shares, color=['b', 'green', 'red', 'yellow']) # Customizing the title appearance plt.title('Percentage of users of programming languages', loc='left', fontsize=15, color='indigo') plt.show()
copy

Here we placed the title on the left, made the font larger and changed the font color. Most of the time you will only care about these parameters, however, you can always refer to the documentation for more information.

Tarefa

The code in this task creates a line plot for the average Boston and Seattle yearly temperatures. Your task is the following:

  1. Use the correct function to set the title for the plot.
  2. Set the following title: 'Boston and Seattle average yearly temperatures'.
  3. Set the font size of the title to be 15.
  4. Set the location of the title to right.

Tarefa

The code in this task creates a line plot for the average Boston and Seattle yearly temperatures. Your task is the following:

  1. Use the correct function to set the title for the plot.
  2. Set the following title: 'Boston and Seattle average yearly temperatures'.
  3. Set the font size of the title to be 15.
  4. Set the location of the title to right.

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Choosing a Title

First of all, a good plot should have a concise yet meaningful title. Titles, such as "Line plot" or "Scatter plot" are too abstract and give us no insight about the purpose of the plot or its data. An example of a good title is "New York Average Monthly Temperatures (2022)", since we understand what the data is, the place and time period to which our data is related (these aspects are important in our example).

Now let’s have a look how we can set a plot title in matplotlib:

1234567
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] plt.bar(programming_languages, shares, color=['b', 'green', 'red', 'yellow']) # Setting the plot title plt.title('Percentage of users of programming languages') plt.show()
copy

Setting a Title

In order to set a title, we simply use the plt.title() function passing a title as a string. However, there is actually more to it. In addition to the first parameter label, we can modify the font size via the fontsize parameter (10 is a default value) and font color via color (there are more options to font customization, but these two are the most important).

Another important parameter is loc (location) which can take either of the values: center (default), left and right.

Let’s now modify the title in our example:

12345678
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] plt.bar(programming_languages, shares, color=['b', 'green', 'red', 'yellow']) # Customizing the title appearance plt.title('Percentage of users of programming languages', loc='left', fontsize=15, color='indigo') plt.show()
copy

Here we placed the title on the left, made the font larger and changed the font color. Most of the time you will only care about these parameters, however, you can always refer to the documentation for more information.

Tarefa

The code in this task creates a line plot for the average Boston and Seattle yearly temperatures. Your task is the following:

  1. Use the correct function to set the title for the plot.
  2. Set the following title: 'Boston and Seattle average yearly temperatures'.
  3. Set the font size of the title to be 15.
  4. Set the location of the title to right.

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 3. Capítulo 1
Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt