MarcosRodrigo commited on
Commit
4b072fd
·
verified ·
1 Parent(s): 5f292fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -17
app.py CHANGED
@@ -373,22 +373,26 @@ elif menu == "Graph":
373
  selected_users = [user for user, visible in user_data.items() if visible]
374
  filtered_item_counts = item_counts[item_counts['Item'].isin(selected_items) & item_counts['User'].isin(selected_users)]
375
 
376
- # Create a line plot for each selected item over time
377
- plt.figure(figsize=(12, 6))
378
- sns.lineplot(data=filtered_item_counts, x='Date', y='Count', hue='Item', marker='o')
379
-
380
- # Customize the plot to show integer y-axis labels
381
- y_max = filtered_item_counts['Count'].max() + 1
382
- plt.yticks(range(0, y_max)) # Show only integer labels on the y-axis
383
-
384
- # Customize the plot
385
- plt.xticks(rotation=45)
386
- plt.title('Item Selections Over Time')
387
- plt.xlabel('Date')
388
- plt.ylabel('Number of Selections')
389
- plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=3)
390
-
391
- # Display the plot
392
- st.pyplot(plt.gcf())
 
 
 
 
393
  else:
394
  st.write("No historical data available to plot.")
 
373
  selected_users = [user for user, visible in user_data.items() if visible]
374
  filtered_item_counts = item_counts[item_counts['Item'].isin(selected_items) & item_counts['User'].isin(selected_users)]
375
 
376
+ # Check if there is data to display
377
+ if not filtered_item_counts.empty:
378
+ # Create a line plot for each selected item over time
379
+ plt.figure(figsize=(12, 6))
380
+ sns.lineplot(data=filtered_item_counts, x='Date', y='Count', hue='Item', marker='o')
381
+
382
+ # Customize the y-axis to show only integer labels
383
+ y_max = max(filtered_item_counts['Count'].max() + 1, 1) # Set y_max to at least 1 to avoid errors
384
+ plt.yticks(range(0, y_max)) # Show only integer labels on the y-axis
385
+
386
+ # Customize the plot
387
+ plt.xticks(rotation=45)
388
+ plt.title('Item Selections Over Time')
389
+ plt.xlabel('Date')
390
+ plt.ylabel('Number of Selections')
391
+ plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=3)
392
+
393
+ # Display the plot
394
+ st.pyplot(plt.gcf())
395
+ else:
396
+ st.write("No data to display. Please select at least one user and one item.")
397
  else:
398
  st.write("No historical data available to plot.")