Fixed line color not changing issue
Browse files1 unmodified line234567891011121314153 unmodified lines192021222324251 unmodified lineimport matplotlib.pyplot as pltimport gradio as grimport matplotlib.colors as mcolorsimport osdef plot_function(func_str, x_min, x_max, resolution, color, linestyle, grid):try:# Ensure a valid color (default to black if None)color = color if color else "#000000"rgb_color = mcolors.hex2color(color) # Convert HEX to RGBx_values = np.linspace(x_min, x_max, resolution)functions = func_str.split(",")3 unmodified linesfunc_text = func_text.strip()func = lambda x: eval(func_text, {"x": x, "np": np})y_values = func(x_values)plt.plot(x_values, y_values, label=f"f(x) = {func_text}", color=rgb_color, linestyle=linestyle)plt.xlabel("x")plt.ylabel("f(x)")1 unmodified line2345678910111213141516173 unmodified lines212223242526271 unmodified lineimport matplotlib.pyplot as pltimport gradio as grimport matplotlib.colors as mcolorsimport os # For handling file pathsdef plot_function(func_str, x_min, x_max, resolution, color, linestyle, grid):try:# Ensure a valid color (default to black if None or invalid)if not color or not color.startswith("#") or len(color) != 7:color = "#000000" # Default to blackrgba_color = mcolors.to_rgba(color) # Convert HEX to RGBAx_values = np.linspace(x_min, x_max, resolution)functions = func_str.split(",")3 unmodified linesfunc_text = func_text.strip()func = lambda x: eval(func_text, {"x": x, "np": np})y_values = func(x_values)plt.plot(x_values, y_values, label=f"f(x) = {func_text}", color=rgba_color, linestyle=linestyle)plt.xlabel("x")plt.ylabel("f(x)")
app.py+8-6