Docsity

Graficas python_______, Ejercicios de Informática

Toggle sidebar
bg1
import numpy as np
import matplotlib.pyplot as plt
def graficar_dos_graficas():
x = np.linspace(-10, 10, 100)
y1 = x**2 + 4
y2 = 3*x**2 + 1*x + 3
# Crear una figura con dos subplots
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(6, 8))
# Gráfica a la derecha
ax1.plot(x, y1, 'b-')
ax1.set_title('Gráfico 1')
ax1.set_xlabel('x')
ax1.set_ylabel('f(x)')
ax1.legend(['𝑓(𝑥) = 𝑥^2 + 4'])
# Gráfica encima
ax2.plot(x, y2, 'g--')
ax2.set_title('Gráfico 2')
ax2.set_xlabel('x')
ax2.set_ylabel('f(x)')
ax2.legend(['𝑓(𝑥) = 3𝑥^2 + 1𝑥 + 3'])
# Ajustar los subplots
plt.tight_layout()
# Mostrar la figura
plt.show()
graficar_dos_graficas()

Vista previa parcial del texto

¡Descarga Graficas python_______ y más Ejercicios en PDF de Informática solo en Docsity!

import numpy as np import matplotlib.pyplot as plt def graficar_dos_graficas(): x = np.linspace(-10, 10, 100) y1 = x2 + 4 y2 = 3x2 + 1x + 3

Crear una figura con dos subplots

fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(6, 8))

Gráfica a la derecha

ax1.plot(x, y1, 'b-') ax1.set_title('Gráfico 1') ax1.set_xlabel('x') ax1.set_ylabel('f(x)') ax1.legend(['𝑓(𝑥) = 𝑥^2 + 4'])

Gráfica encima

ax2.plot(x, y2, 'g--') ax2.set_title('Gráfico 2') ax2.set_xlabel('x') ax2.set_ylabel('f(x)') ax2.legend(['𝑓(𝑥) = 3𝑥^2 + 1𝑥 + 3'])

Ajustar los subplots

plt.tight_layout()

Mostrar la figura

plt.show() graficar_dos_graficas()