Conteúdo do Curso
Visualization in Python with matplotlib
Visualization in Python with matplotlib
Adding One More Line
Quite good! That's a good visualization! Let's expand our chart with new data.
We may want to compare the emission levels by displaying several lines on a single chart. It can be easily done by calling the .plot()
method of Axes
object multiple times. For instance, if you call ax.plot()
two times, you will get two lines on one chart. By default, the first line will be blue, the second one will be orange.
# Import the libraries import matplotlib.pyplot as plt import pandas as pd # Load the data data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/ed80401e-2684-4bc4-a077-99d13a386ac7/co2.csv', index_col = 0) # Filter the data ita = data.loc['Italy'] swe = data.loc['Sweden'] # Create Figure and Axes objects fig, ax = plt.subplots() # Initialize lines ax.plot(ita.index.astype(int), ita.values) ax.plot(swe.index.astype(int), swe.values) # Display the plot plt.show()
Obrigado pelo seu feedback!