xoarissa commited on
Commit
a416c13
·
1 Parent(s): 561ec65

Fixed line color issue (ensured valid HEX format)

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -6,11 +6,12 @@ import os # For handling file paths
6
 
7
  def plot_function(func_str, x_min, x_max, resolution, color, linestyle, grid):
8
  try:
9
- # Ensure a valid color (default to black if None or invalid)
10
  if not color or not color.startswith("#") or len(color) != 7:
11
  color = "#000000" # Default to black
12
 
13
- rgba_color = mcolors.to_rgba(color) # Convert HEX to RGBA
 
14
 
15
  x_values = np.linspace(x_min, x_max, resolution)
16
  functions = func_str.split(",")
@@ -21,7 +22,7 @@ def plot_function(func_str, x_min, x_max, resolution, color, linestyle, grid):
21
  func_text = func_text.strip()
22
  func = lambda x: eval(func_text, {"x": x, "np": np})
23
  y_values = func(x_values)
24
- plt.plot(x_values, y_values, label=f"f(x) = {func_text}", color=rgba_color, linestyle=linestyle)
25
 
26
  plt.xlabel("x")
27
  plt.ylabel("f(x)")
 
6
 
7
  def plot_function(func_str, x_min, x_max, resolution, color, linestyle, grid):
8
  try:
9
+ # Ensure the color is always a valid HEX string
10
  if not color or not color.startswith("#") or len(color) != 7:
11
  color = "#000000" # Default to black
12
 
13
+ # Convert to proper HEX format for Matplotlib
14
+ color = mcolors.to_hex(color)
15
 
16
  x_values = np.linspace(x_min, x_max, resolution)
17
  functions = func_str.split(",")
 
22
  func_text = func_text.strip()
23
  func = lambda x: eval(func_text, {"x": x, "np": np})
24
  y_values = func(x_values)
25
+ plt.plot(x_values, y_values, label=f"f(x) = {func_text}", color=color, linestyle=linestyle)
26
 
27
  plt.xlabel("x")
28
  plt.ylabel("f(x)")