'How do I plot the indifference curves and budget line for the utility function [log(x)+log(y)]^1/2?

I'm taking a free course on Economic Modeling using python at quantecon.org. One of the topics is optimization, and the example given is very simple. So I decided to try one of my own.

I've tried experimenting with U = [log(x) + log(y)]^1/2 but for some reason I can't plot the indifference curves properly. Also, given a budget of 10, price of x1 = 1, x2 = 2.5, how would I plot the budget line?

from math import log
from math import e
import numpy as np
import matplotlib.pyplot as plt

def A_indifference(B, ubar):
return ((e**ubar**2)/B)

def plot_indifference_curves(ax):
ubar = np.arange(1, 5, 1)
ax.plot(B, A_indifference(B, ubar))
ax.legend([r"$\bar{U}$" + " = {}".format(i) for i in ubar])
ax.set_xlabel("B")
ax.set_ylabel(r"$A(B, \bar{U}$)")


B = np.linspace(1, 20, 100).reshape((100, 1))
fig, ax = plt.subplots()
plot_indifference_curves(ax)

My code until here, and my plot results: Plot with only one indifference curve showing

How I would like to be: enter image description here

If anyone wants to take a look at the code used in the course for some reason: https://datascience.quantecon.org/scientific/optimization.html#:~:text=not%20be%20optimal.-,Optimal%20Choice,-%C2%B6



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source