Python:Why is plt.axhline(y=0.0 ...) not at y=0?

22 views Asked by At

Why does the same code produce different results when run in PyCharm and VSCode, even though the environments are both configured with Anaconda? enter image description here

from scipy.integrate import odeint
import matplotlib.pyplot as plt
import numpy as np

# Define parameters
N = 1e7  # Total population
lamuda = 0.2  # Average number of contacts per day
mu = 0.08  # Probability of being cured and recovered is 0.08
I0 = 100  # Initial number of infected individuals
i0 = I0 / N  # Initial proportion of infected individuals
s0 = (N - I0) / N  # Initial proportion of susceptible individuals
tend = 200  # Prediction days is 200
t = np.arange(0.0, tend, 1)  # (start, stop, step)

# SIR model:
def dySIR(y, t, lamuda, mu):
    i, s = y
    di_dt = lamuda * s * i - mu * i
    ds_dt = -lamuda * s * i
    return [di_dt, ds_dt]

# Recovered individuals proportion is represented by 1 - s - i
Y0 = (i0, s0)  # Set initial values

# Numerical solution of the equations
ySIR = odeint(dySIR, Y0, t, args=(lamuda, mu))

# Plotting
plt.xlabel('t')
plt.axis([0, tend, -0.1, 1.1])
plt.axhline(y=0.0 ,ls="--",c='c')  # Add horizontal line
plt.plot(t, ySIR[:,0], '-r', label='i(t)-SIR')
plt.plot(t, ySIR[:,1], '-b', label='s(t)-SIR')
plt.plot(t, 1 - ySIR[:,0] - ySIR[:,1], '-m', label='r(t)-SIR')
plt.legend(loc='best')  
plt.show()

The issue lies in this line of code: plt.axhline(y=0.0 ,ls="--",c='c')

vscode:enter image description here

pycharm:enter image description here

Both the VSCode and PyCharm environments are configured with Anaconda using Python 3.11.7.

0

There are 0 answers