Python | Adding Phi to Plot Label

Here, we are going to learn about the adding phi to plot label and its Python implementation.
Submitted by Anuj Singh, on August 31, 2020

Phi is a very oftenly used greek mathematical letter. They are mostly used in physics and other mathematical expressions, especially, when there is topic related change (for example charge and electrodynamics) and therefore, they have registered an importance in languages.

Therefore, matplotlib has defined a command for usage.

In this article, we are going to add ɸ using a command in matplotlib.

plt.text(3, 0.4, r'$\nabla=100$')
#Adding ɸ as text
Python | Adding Phi to Plot Label (1)
plt.title('nabla 'r'$\nabla=100$')
#Adding ɸ in title of the figure
Python | Adding Phi to Plot Label (2)
plt.xlabel('nabla ('r'$\nabla=100)$')
#Adding ɸ in x axis label of the figure
Python | Adding Phi to Plot Label (3)
plt.ylabel('nabla ('r'$\nabla=100)$')
#Adding ɸ in y axis label of the figure
Python | Adding Phi to Plot Label (4)

Python code for adding phi to plot label

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(10)
y = np.cos(x)*np.exp(x/5)

#  phi
#In text
plt.figure()
plt.plot(x,y, '-o', color=  'purple')
plt.title('phi')
plt.text(3, -2.2, r'$\phi=100$')
plt.show()

#In title
plt.figure()
plt.plot(x,y, '-o', color=  'purple')
plt.title('  phi 'r'$\phi=100$')
plt.show()

#In x-axis label
plt.figure()
plt.plot(x,y, '-o', color=  'purple')
plt.xlabel('  phi ('r'$\phi=100)$')
plt.show()

#In y-axis label
plt.figure()
plt.plot(x,y, '-o', color=  'purple')
plt.ylabel('  phi ('r'$\phi=100)$')
plt.show()

Output:

Output is as Figure


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.