Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Changing Line Style | Basics: Line Charts
Visualization in Python with matplotlib

bookChanging Line Style

Good! More customizing stuff to go!

Additionally, we can customize more line parameters, such as color, line style, points style. These are the simplest, but the .plot() function has many more parameters available to set (you can read about this in the documentation). Let's consider all of the mentioned parameters:

For example, let's modify our example plot even more!

1234567891011121314151617181920212223242526
# 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, label = 'Italy', color = 'green', marker = '1', linestyle = '--') ax.plot(swe.index.astype(int), swe.values, label = 'Sweden', color = 'blue', marker = 'v', linestyle = ':') # Add axis labels ax.set_xlabel('Year') ax.set_ylabel('CO2 emission level (tonnes per person)') # Display the legend, title, and plot plt.legend() plt.title('CO2 Emission Levels in Italy and Sweden') plt.show()
copy

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 10

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Awesome!

Completion rate improved to 2.94

bookChanging Line Style

Swipe um das Menü anzuzeigen

Good! More customizing stuff to go!

Additionally, we can customize more line parameters, such as color, line style, points style. These are the simplest, but the .plot() function has many more parameters available to set (you can read about this in the documentation). Let's consider all of the mentioned parameters:

For example, let's modify our example plot even more!

1234567891011121314151617181920212223242526
# 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, label = 'Italy', color = 'green', marker = '1', linestyle = '--') ax.plot(swe.index.astype(int), swe.values, label = 'Sweden', color = 'blue', marker = 'v', linestyle = ':') # Add axis labels ax.set_xlabel('Year') ax.set_ylabel('CO2 emission level (tonnes per person)') # Display the legend, title, and plot plt.legend() plt.title('CO2 Emission Levels in Italy and Sweden') plt.show()
copy

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 10
some-alt