Contenido del Curso
Ultimate Visualization with Python
Ultimate Visualization with Python
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
:
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()
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:
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()
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.
Tarea
The code in this task creates a line plot for the average Boston and Seattle yearly temperatures. Your task is the following:
- Use the correct function to set the title for the plot.
- Set the following title:
'Boston and Seattle average yearly temperatures'
. - Set the font size of the title to be
15
. - Set the location of the title to
right
.
¡Gracias por tus comentarios!
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
:
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()
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:
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()
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.
Tarea
The code in this task creates a line plot for the average Boston and Seattle yearly temperatures. Your task is the following:
- Use the correct function to set the title for the plot.
- Set the following title:
'Boston and Seattle average yearly temperatures'
. - Set the font size of the title to be
15
. - Set the location of the title to
right
.
¡Gracias por tus comentarios!
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
:
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()
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:
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()
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.
Tarea
The code in this task creates a line plot for the average Boston and Seattle yearly temperatures. Your task is the following:
- Use the correct function to set the title for the plot.
- Set the following title:
'Boston and Seattle average yearly temperatures'
. - Set the font size of the title to be
15
. - Set the location of the title to
right
.
¡Gracias por tus comentarios!
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
:
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()
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:
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()
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.
Tarea
The code in this task creates a line plot for the average Boston and Seattle yearly temperatures. Your task is the following:
- Use the correct function to set the title for the plot.
- Set the following title:
'Boston and Seattle average yearly temperatures'
. - Set the font size of the title to be
15
. - Set the location of the title to
right
.