5 Best Ways to Insert a Degree Symbol into a Python Plot Using Matplotlib

Rate this post

💡 Problem Formulation: When creating plots in Python using Matplotlib, it’s often necessary to include units of measurement, which can include the degree symbol (°) for temperature, angles, etc. For example, when plotting temperature data, we want to label the y-axis with “Temperature (°C)” to indicate Celsius. This article will explore five methods to insert a degree symbol into a Matplotlib plot effectively.

Method 1: Using Unicode

One straightforward approach to include a degree symbol in a Matplotlib plot is by using Unicode. The Unicode character for the degree symbol is u"\u00B0". This method allows direct insertion of special characters into labels, titles, and annotations within your plot.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ("+r"$^\circ$"+"C)")
plt.show()

The plot generated will have the y-axis labeled with “Temperature (°C)”, with the degree symbol formatted by LaTeX.

Method 3: HTML Entity

HTML entities can also be used in Matplotlib text fields. The HTML entity for a degree symbol is °. While this method is less common, it is still useful if you are already familiar with HTML entities.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel(f"Temperature ({u'\u00B0'}C)")
plt.show()

This code example will create a simple line plot and label the y-axis with “Temperature (°C)”, incorporating the degree symbol.

Method 2: Using LaTeX

Matplotlib supports LaTeX, a typesetting system that’s excellent for including mathematical notation. To include a degree symbol, you can use the LaTeX notation r"$^\circ$". This method offers high-quality text rendering.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ("+r"$^\circ$"+"C)")
plt.show()

The plot generated will have the y-axis labeled with “Temperature (°C)”, with the degree symbol formatted by LaTeX.

Method 3: HTML Entity

HTML entities can also be used in Matplotlib text fields. The HTML entity for a degree symbol is °. While this method is less common, it is still useful if you are already familiar with HTML entities.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel(f"Temperature ({u'\u00B0'}C)")
plt.show()

This code example will create a simple line plot and label the y-axis with “Temperature (°C)”, incorporating the degree symbol.

Method 2: Using LaTeX

Matplotlib supports LaTeX, a typesetting system that’s excellent for including mathematical notation. To include a degree symbol, you can use the LaTeX notation r"$^\circ$". This method offers high-quality text rendering.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ("+r"$^\circ$"+"C)")
plt.show()

The plot generated will have the y-axis labeled with “Temperature (°C)”, with the degree symbol formatted by LaTeX.

Method 3: HTML Entity

HTML entities can also be used in Matplotlib text fields. The HTML entity for a degree symbol is °. While this method is less common, it is still useful if you are already familiar with HTML entities.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel(f"Temperature ({u'\u00B0'}C)")
plt.show()

This code example will create a simple line plot and label the y-axis with “Temperature (°C)”, incorporating the degree symbol.

Method 2: Using LaTeX

Matplotlib supports LaTeX, a typesetting system that’s excellent for including mathematical notation. To include a degree symbol, you can use the LaTeX notation r"$^\circ$". This method offers high-quality text rendering.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ("+r"$^\circ$"+"C)")
plt.show()

The plot generated will have the y-axis labeled with “Temperature (°C)”, with the degree symbol formatted by LaTeX.

Method 3: HTML Entity

HTML entities can also be used in Matplotlib text fields. The HTML entity for a degree symbol is °. While this method is less common, it is still useful if you are already familiar with HTML entities.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ("+r"$^\circ$"+"C)")
plt.show()

The plot generated will have the y-axis labeled with “Temperature (°C)”, with the degree symbol formatted by LaTeX.

Method 3: HTML Entity

HTML entities can also be used in Matplotlib text fields. The HTML entity for a degree symbol is °. While this method is less common, it is still useful if you are already familiar with HTML entities.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel(f"Temperature ({u'\u00B0'}C)")
plt.show()

This code example will create a simple line plot and label the y-axis with “Temperature (°C)”, incorporating the degree symbol.

Method 2: Using LaTeX

Matplotlib supports LaTeX, a typesetting system that’s excellent for including mathematical notation. To include a degree symbol, you can use the LaTeX notation r"$^\circ$". This method offers high-quality text rendering.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ("+r"$^\circ$"+"C)")
plt.show()

The plot generated will have the y-axis labeled with “Temperature (°C)”, with the degree symbol formatted by LaTeX.

Method 3: HTML Entity

HTML entities can also be used in Matplotlib text fields. The HTML entity for a degree symbol is °. While this method is less common, it is still useful if you are already familiar with HTML entities.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ("+r"$^\circ$"+"C)")
plt.show()

The plot generated will have the y-axis labeled with “Temperature (°C)”, with the degree symbol formatted by LaTeX.

Method 3: HTML Entity

HTML entities can also be used in Matplotlib text fields. The HTML entity for a degree symbol is °. While this method is less common, it is still useful if you are already familiar with HTML entities.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel(f"Temperature ({u'\u00B0'}C)")
plt.show()

This code example will create a simple line plot and label the y-axis with “Temperature (°C)”, incorporating the degree symbol.

Method 2: Using LaTeX

Matplotlib supports LaTeX, a typesetting system that’s excellent for including mathematical notation. To include a degree symbol, you can use the LaTeX notation r"$^\circ$". This method offers high-quality text rendering.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ("+r"$^\circ$"+"C)")
plt.show()

The plot generated will have the y-axis labeled with “Temperature (°C)”, with the degree symbol formatted by LaTeX.

Method 3: HTML Entity

HTML entities can also be used in Matplotlib text fields. The HTML entity for a degree symbol is °. While this method is less common, it is still useful if you are already familiar with HTML entities.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ("+r"$^\circ$"+"C)")
plt.show()

The plot generated will have the y-axis labeled with “Temperature (°C)”, with the degree symbol formatted by LaTeX.

Method 3: HTML Entity

HTML entities can also be used in Matplotlib text fields. The HTML entity for a degree symbol is °. While this method is less common, it is still useful if you are already familiar with HTML entities.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel(f"Temperature ({u'\u00B0'}C)")
plt.show()

This code example will create a simple line plot and label the y-axis with “Temperature (°C)”, incorporating the degree symbol.

Method 2: Using LaTeX

Matplotlib supports LaTeX, a typesetting system that’s excellent for including mathematical notation. To include a degree symbol, you can use the LaTeX notation r"$^\circ$". This method offers high-quality text rendering.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ("+r"$^\circ$"+"C)")
plt.show()

The plot generated will have the y-axis labeled with “Temperature (°C)”, with the degree symbol formatted by LaTeX.

Method 3: HTML Entity

HTML entities can also be used in Matplotlib text fields. The HTML entity for a degree symbol is °. While this method is less common, it is still useful if you are already familiar with HTML entities.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ("+r"$^\circ$"+"C)")
plt.show()

The plot generated will have the y-axis labeled with “Temperature (°C)”, with the degree symbol formatted by LaTeX.

Method 3: HTML Entity

HTML entities can also be used in Matplotlib text fields. The HTML entity for a degree symbol is °. While this method is less common, it is still useful if you are already familiar with HTML entities.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.
import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel(f"Temperature ({u'\u00B0'}C)")
plt.show()

This code example will create a simple line plot and label the y-axis with “Temperature (°C)”, incorporating the degree symbol.

Method 2: Using LaTeX

Matplotlib supports LaTeX, a typesetting system that’s excellent for including mathematical notation. To include a degree symbol, you can use the LaTeX notation r"$^\circ$". This method offers high-quality text rendering.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ("+r"$^\circ$"+"C)")
plt.show()

The plot generated will have the y-axis labeled with “Temperature (°C)”, with the degree symbol formatted by LaTeX.

Method 3: HTML Entity

HTML entities can also be used in Matplotlib text fields. The HTML entity for a degree symbol is °. While this method is less common, it is still useful if you are already familiar with HTML entities.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

Applying this snippet will give you the same visual result on the plot, showing y-axis labels with a degree symbol.

Method 4: Using the Matplotlib Degree Symbol

Matplotlib provides a specific degree symbol attribute plt.rcParams['text.usetex'] = True alongside plt.degrees() which can be used to ensure consistency across different operating systems and environments.

Here’s an example:

import matplotlib.pyplot as plt

plt.rcParams['text.usetex'] = True
plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature ($\degree$C)")
plt.show()

With this setting enabled, the degree symbol will be consistently rendered in the plot, creating a professional appearance.

Bonus One-Liner Method 5: Direct Character Insertion

If your keyboard allows it or you have the degree symbol in your clipboard, you can directly paste or type it into the Matplotlib string. This method is quick and easy, but depends on the availability of the symbol on your input device.

Here’s an example:

import matplotlib.pyplot as plt

plt.plot([0, 1, 2], [30, 25, 40])
plt.title("Temperature Profile")
plt.ylabel("Temperature (°C)")
plt.show()

This simplistic approach will also produce a plot with the degree symbol appearing on the y-axis, requiring minimal effort.

Summary/Discussion

  • Method 1: Unicode. Straightforward and doesn’t require additional settings or syntax. Limited to Unicode-supported characters and some fonts may not render the symbol correctly.
  • Method 2: LaTeX. Provides high-quality text rendering and a vast array of symbols. However, it can be slower to render and may require some familiarity with LaTeX syntax.
  • Method 3: HTML Entity. Useful for those familiar with HTML. It’s less known and perhaps less intuitive than other methods.
  • Method 4: Matplotlib Degree Symbol. Ensures environment consistency and quality rendering. It requires additional configuration, which might be unnecessary for simple plots.
  • Bonus Method 5: Direct Character Insertion. The simplest method, but depends on your keyboard layout or having the symbol handy to copy and paste.