Fixed color picker issue (ensured HEX format & RGBA conversion)
Browse files123456788991011121314151617184 unmodified lines23242522262728293 unmodified lines3334353236373839import numpy as npimport matplotlib.pyplot as pltimport gradio as grimport matplotlib.colors as mcolorsimport os
def plot_function(func_str, x_min, x_max, resolution, color, linestyle, grid): try: # Ensure color is valid (fallback to black if empty) if not color: # Ensure color is in proper HEX format if not color or not color.startswith("#") or len(color) != 7: color = "#000000" # Default to black
# Convert to Matplotlib-compatible RGBA format color = mcolors.to_rgba(color)
x_values = np.linspace(x_min, x_max, resolution) functions = func_str.split(",")
4 unmodified lines func = lambda x: eval(func_text, {"x": x, "np": np}) y_values = func(x_values)
# Use HEX color directly without conversion # Use RGBA color format (Matplotlib-compatible) plt.plot(x_values, y_values, label=f"f(x) = {func_text}", color=color, linestyle=linestyle)
plt.xlabel("x")3 unmodified lines if grid: plt.grid()
# Save the plot correctly and return an absolute path # Save the plot and return absolute path plot_filename = "high_res_plot.png" abs_path = os.path.abspath(plot_filename) # Convert to absolute path plt.savefig(abs_path, dpi=300)app.py+8-4