How to plot a function with multiple parameters on the same set of axes

In summary, the conversation discusses code and plot explanations, variables and constants used, functions for calculating and computing, and a plot with different values for gamma. It also suggests adding a label option to the plot to differentiate between the different gamma values and create a legend.
  • #1
Daniel Lima
3
2
TL;DR Summary
I'm currently trying to plot a graph wich describes a photoionization cross section as a function of incident photon energy for optical transition in a semiconductor for different values of the γ factor. But the the outcome is pretty different of what it should be, as one can see in the attachments
I attached a file with some explanations of the variables in the code and the plot that I should get. I don't know what is wrong. Any help will appreciated.
Python:
from scipy.integrate import quad
import numpy as np
from scipy.special import gamma as gamma_function
from scipy.constants import  e
import matplotlib.pyplot as plt

#Constants
epsilon = 13.1          # dielectric constant of the material
gamma_C = 0.5           # donor impurity linewidth
nr = 3.2                # refractive index of semiconductor
flux = 0.0              # Phi in eqn 8 magnetic flux
R = 5.0                 # radius of the quantum ring in nm
hbar = 1.0        # reduced Planck constant in eV
h = 2*np.pi*hbar          # Planck constant in eV
c = 1.0
alpha = e**2/hbar*c
R = 5  # nm
r = np.linspace(0, 6 * R,100)
nu = np.linspace(0,100, 100)
# Function that calculates the integrand
def func(rho):
    betai = gamma**2 / 2.0
    betaf = np.sqrt(1.0 + gamma**4 / 4.0)
    return (gamma * rho)**(betai + betaf) * np.exp(-0.5 * (gamma * rho)**2) * rho**2

def compute_matrix_element(gamma):  
    betai = gamma**2 / 2.0
    betaf = np.sqrt(1.0 + gamma**4 / 4.0)
    integral = quad(func, 0, np.infty)[0]
    first_sqrt  = (1.0 / (2.0**betai * gamma_function(betai + 1)))**0.5
    second_sqrt = (1.0 / (2.0**betaf * gamma_function(betaf + 1)))**0.5
    return gamma**2 / 2.0 / np.pi * R * first_sqrt * second_sqrt * integral

def compute_cross_section(hnu, gamma):
    # function that calculates the photoionisation cross section
    betai = gamma**2 / 2.0
    betaf = np.sqrt(1.0 + gamma**4 / 2.0)
    Ei = gamma**2 * (1.0 + betai) - gamma**4 / 2.0
    Ef = gamma**2 * (1.0 + betaf) - gamma**4 / 2.0
    delta = hbar / np.pi * gamma_C / ( nu - (Ef - Ei )**2 + (hbar * gamma_C)**2)
    matrix_element = compute_matrix_element(gamma)
    return nr / epsilon * 4.0 * np.pi / 3.0 * alpha * h*nu * (abs(matrix_element))**2 * delta

#Plot
plt.figure()
for gamma in [1.0, 1.5, 2.0]:
    plt.plot(h*nu, (compute_cross_section(h*nu, gamma)))
  
plt.legend(['$\gamma = 1.0$', '$\gamma = 1.5$', '$\gamma = 2.0$'] )
plt.ylabel('$\\times$-section $\sigma$ (cm$^{2}$)')
plt.xlabel('Photon energy $h\\nu$ (meV)')
plt.xlim(0,100)
plt.show()
 

Attachments

  • cross-section.pdf
    104.8 KB · Views: 247
  • PCS.pdf
    33.1 KB · Views: 216
Last edited by a moderator:
Technology news on Phys.org
  • #2
Here's an example:

https://www.w3resource.com/graphics/matplotlib/basic/matplotlib-basic-exercise-5.php

It looks like the label setting defines a new plot line within plot so try adding a label option using the gamma value of the loop.

Python:
plt.figure()
for gamma in [1.0, 1.5, 2.0]:
    plt.plot(h*nu, (compute_cross_section(h*nu, gamma)), label="Gamma: "+str(gamma))

or alternatively:

Python:
plt.figure()
for gamma in [1.0, 1.5, 2.0]:
    plt.plot(h*nu, (compute_cross_section(h*nu, gamma)), label="Gamma: %3.1f"%gamma)
 
  • #3
Not quite sure if I understood what you're saying. Should I change the label to put the gama variable on it?
 
  • #4
Did you try it?

Yes, the label must be different between plots. I guess you could say its a key, a means to label the plot data as different from other plot dat being plotted. It also likely is used in making the legends box for the chart.
 
  • #5
I tried but nothing has changed. Could it be something else?
 
  • #6
Daniel Lima said:
I tried but nothing has changed. Could it be something else?
Uh ... you think ?
 
  • #7
Daniel Lima said:
I tried but nothing has changed. Could it be something else?
Just remember, Sir:
“When you have exhausted all possibilities, remember this - you haven't.”

― Thomas Edison
 
  • Like
Likes phinds

1. How do I specify multiple parameters for a function plot?

To plot a function with multiple parameters on the same set of axes, you can use the syntax "f(x, y)" to define the function. Here, "x" and "y" represent the two parameters that will be varied in the plot.

2. Can I plot more than two parameters on the same set of axes?

Yes, you can plot multiple parameters on the same set of axes by using the syntax "f(x, y, z)" to define the function. Here, "x", "y", and "z" represent the three parameters that will be varied in the plot.

3. How do I label the axes for a function plot with multiple parameters?

To label the axes for a function plot with multiple parameters, you can use the "xlabel" and "ylabel" functions in your coding language. These functions allow you to specify the names of the axes, such as "x" and "y" for a two-parameter plot.

4. Can I change the color or style of the plot for each parameter?

Yes, you can specify the color or style for each parameter in your function plot by using the "color" and "linestyle" parameters in your coding language. This allows you to create a visually appealing plot with different colors or styles for each parameter.

5. Is it possible to add a legend for a function plot with multiple parameters?

Yes, you can add a legend to your function plot with multiple parameters by using the "legend" function in your coding language. This allows you to label each parameter and make it easier to interpret the plot.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Programming and Computer Science
Replies
3
Views
931
  • Programming and Computer Science
Replies
3
Views
2K
  • Advanced Physics Homework Help
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
864
Replies
2
Views
4K
  • Programming and Computer Science
Replies
9
Views
4K
  • Advanced Physics Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
10
Views
10K
  • Programming and Computer Science
Replies
2
Views
16K
Back
Top