Necesito un gráfico con ese código

import matplotlib.pyplot as plt
import numpy as np

Define los valores de P y la función de demanda agregada DA

P = np.linspace(1, 100, 400)
Y = 72.38 + 8.51 / P

Crear el gráfico

plt.figure(figsize=(10, 6))
plt.plot(P, Y, label=‘Curva de Demanda Agregada (DA)’, color=‘b’)
plt.xlabel(‘Nivel de Precios (P)’)
plt.ylabel(‘Ingreso (Y)’)
plt.title(‘Curva de Demanda Agregada (DA)’)
plt.legend()
plt.grid(True)
plt.gca().invert_xaxis() # Invertir el eje x para mostrar el efecto típico
plt.show()

Hi,

I just tested the code, it is working fine. The only discrepancy that I found when I copied and pasted it onto my console for testing is that the apostrophes for quotes did not directly translate to the correct ones from the key that is directly to the left of the Return Key from the keyboard.

here is your code snippet:

import matplotlib.pyplot as plt
import numpy as np

P = np.linspace(1, 100, 400)
Y = 72.38 + 8.51 / P

plt.figure(figsize=(10, 6))
plt.plot(P, Y, label='Curva de Demanda Agregada (DA)', color='b')
plt.xlabel('Nivel de Precios (P)')
plt.ylabel('Ingreso (Y)')
plt.title('Curva de Demanda Agregada (DA)')
plt.legend()
plt.grid(True)
plt.gca().invert_xaxis() # Invertir el eje x para mostrar el efecto típico
plt.show()
1 Like

That’s because the forum converts them when they aren’t inside a code formatting block.

Point taken. But if that is only a translation error from not pasting using the forum formatting protocol, why would it not work on their system - where the conversion/translation is not taking place?

Oh, I agree with you - there’s nothing apparently wrong with the code. But OP didn’t really ask a question and the translated title is just something like “I need a chart with this code”, so it’s hard to know what to say.

My complete wild guess is that the environment is not set up to support plt.show():