Spaces:
Sleeping
Sleeping
Bachstelze commited on
Commit ·
4d586be
1
Parent(s): 4cd2899
correct linting
Browse files- results/score_board.py +23 -6
results/score_board.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import matplotlib.pyplot as plt
|
| 2 |
-
|
| 3 |
|
| 4 |
def create_score_board(weeks=None, scores=None, save_path=None, show=False):
|
| 5 |
"""
|
|
@@ -30,12 +30,24 @@ def create_score_board(weeks=None, scores=None, save_path=None, show=False):
|
|
| 30 |
fig, ax = plt.subplots(figsize=(8, 6))
|
| 31 |
|
| 32 |
# Plot the data
|
| 33 |
-
ax.plot(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
# Set labels and title
|
| 36 |
ax.set_xlabel('Week', fontsize=12)
|
| 37 |
ax.set_ylabel('R^2 Score', fontsize=12)
|
| 38 |
-
ax.set_title(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Set x-axis ticks to be exactly the weeks
|
| 41 |
ax.set_xticks(weeks)
|
|
@@ -46,15 +58,19 @@ def create_score_board(weeks=None, scores=None, save_path=None, show=False):
|
|
| 46 |
|
| 47 |
# Annotate each point with its score
|
| 48 |
for i, (x, y) in enumerate(zip(weeks, scores)):
|
| 49 |
-
ax.annotate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# Adjust layout to prevent clipping
|
| 52 |
fig.tight_layout()
|
| 53 |
|
| 54 |
# Save the plot if save_path is provided
|
| 55 |
if save_path is not None:
|
| 56 |
-
# Ensure the directory exists
|
| 57 |
-
#os.makedirs(os.path.dirname(save_path), exist_ok=True)
|
| 58 |
# we save it into the main directory
|
| 59 |
fig.savefig(save_path, dpi=300)
|
| 60 |
print(f"Plot saved to {save_path}")
|
|
@@ -65,6 +81,7 @@ def create_score_board(weeks=None, scores=None, save_path=None, show=False):
|
|
| 65 |
|
| 66 |
return fig
|
| 67 |
|
|
|
|
| 68 |
if __name__ == "__main__":
|
| 69 |
# Example usage with default data
|
| 70 |
fig = create_score_board(save_path='score_board.png', show=True)
|
|
|
|
| 1 |
import matplotlib.pyplot as plt
|
| 2 |
+
|
| 3 |
|
| 4 |
def create_score_board(weeks=None, scores=None, save_path=None, show=False):
|
| 5 |
"""
|
|
|
|
| 30 |
fig, ax = plt.subplots(figsize=(8, 6))
|
| 31 |
|
| 32 |
# Plot the data
|
| 33 |
+
ax.plot(
|
| 34 |
+
weeks,
|
| 35 |
+
scores,
|
| 36 |
+
marker='o',
|
| 37 |
+
linestyle='-',
|
| 38 |
+
color='b',
|
| 39 |
+
linewidth=2,
|
| 40 |
+
markersize=8
|
| 41 |
+
)
|
| 42 |
|
| 43 |
# Set labels and title
|
| 44 |
ax.set_xlabel('Week', fontsize=12)
|
| 45 |
ax.set_ylabel('R^2 Score', fontsize=12)
|
| 46 |
+
ax.set_title(
|
| 47 |
+
'R^2 Score Progression Over Weeks',
|
| 48 |
+
fontsize=14,
|
| 49 |
+
fontweight='bold'
|
| 50 |
+
)
|
| 51 |
|
| 52 |
# Set x-axis ticks to be exactly the weeks
|
| 53 |
ax.set_xticks(weeks)
|
|
|
|
| 58 |
|
| 59 |
# Annotate each point with its score
|
| 60 |
for i, (x, y) in enumerate(zip(weeks, scores)):
|
| 61 |
+
ax.annotate(
|
| 62 |
+
f'{y:.2f}',
|
| 63 |
+
(x, y),
|
| 64 |
+
textcoords="offset points",
|
| 65 |
+
xytext=(0, 10),
|
| 66 |
+
ha='center'
|
| 67 |
+
)
|
| 68 |
|
| 69 |
# Adjust layout to prevent clipping
|
| 70 |
fig.tight_layout()
|
| 71 |
|
| 72 |
# Save the plot if save_path is provided
|
| 73 |
if save_path is not None:
|
|
|
|
|
|
|
| 74 |
# we save it into the main directory
|
| 75 |
fig.savefig(save_path, dpi=300)
|
| 76 |
print(f"Plot saved to {save_path}")
|
|
|
|
| 81 |
|
| 82 |
return fig
|
| 83 |
|
| 84 |
+
|
| 85 |
if __name__ == "__main__":
|
| 86 |
# Example usage with default data
|
| 87 |
fig = create_score_board(save_path='score_board.png', show=True)
|