0

I want to Plot V(y axis) vs t(x axis) graph using the below equation at 5 different values of L(shown below)

L= [5,10,15,20,25]

b=0.0032

Equation, (b*V*0.277*t) - (b*L) = log(1+b*V*0.277*t)

code output will be as shown in figure Expected Outcome

1
  • 1
    Please provide enough code so others can better understand or reproduce the problem. Commented Nov 25, 2022 at 16:45

1 Answer 1

2

While sympy exposes the plot_implicit function, the results are far from good. We can use Numpy and Matplotlib to achieve our goal.

The basic idea is that your equation can be written as LHS - RHS = 0. So, we can create contour plots and select the level 0. But contour plots uses colormaps, so we will have to create solid colormaps:

import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib.lines import Line2D
from matplotlib.colors import ListedColormap
import numpy as np

Lvalues = [5,10,15,20,25]
bval = 0.0032

V = np.linspace(0, 1000)
t = np.linspace(0, 10)
V, t = np.meshgrid(V, t)
f = lambda V, t, b, L: b*V*0.277*t - b*L - np.log(1+b*V*0.277*t)

colors = cm.tab10.colors
handles = []
fig, ax = plt.subplots()
for L, c in zip(Lvalues, colors):
    cmap = ListedColormap([c, c])
    z = f(V, t, bval, L)
    ax.contour(t, V, z, levels=[0], cmap=cmap)
    handles.append(Line2D([], [], color=c, label="L = %s" % L))
ax.legend(handles=handles)
plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much for providing the detailed solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.