From ca02b23f41cda8ba06f141597af15a6ff374cdc9 Mon Sep 17 00:00:00 2001 From: Ananya Ravikiran Vastare <116643029+Ananya-vastare@users.noreply.github.com> Date: Tue, 8 Oct 2024 20:25:12 +0530 Subject: [PATCH] Change the graph for better visualization (#23) * Change the graph for better visualization * Changed the graph --------- Co-authored-by: Tanisha Lalwani <145191259+tanishaness@users.noreply.github.com> --- Backend/graph.py | 50 +++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/Backend/graph.py b/Backend/graph.py index 5bd548a..294f2ee 100644 --- a/Backend/graph.py +++ b/Backend/graph.py @@ -1,24 +1,38 @@ import matplotlib.pyplot as plt +import numpy as np import time -import random - -xdata = [] -ydata = [] - + +# Initialize the figure +plt.figure() + +# Set up the axes +plt.axis("off") # Turn off the axis for a cleaner look + +# Create an empty grid for the heatmap +heatmap_data = np.zeros((10, 10)) # 10x10 grid + +# Show the plot window +plt.ion() # Turn on interactive mode plt.show() - -axes = plt.gca() -axes.set_xlim(0, 100) -axes.set_ylim(0,1) -line, = axes.plot(xdata, ydata, 'r-') - + +# Loop to simulate data for the heatmap for i in range(100): - xdata.append(i) - ydata.append(i/2) - line.set_xdata(xdata) - line.set_ydata(ydata) + # Randomly generate data (for example purposes) + data = np.random.rand(10, 10) # Random values between 0 and 1 for a 10x10 grid + heatmap_data += data # Accumulate data for the heatmap + + # Clear the axes and plot the heatmap + plt.clf() # Clear the current figure + heatmap = plt.imshow( + heatmap_data, cmap="hot", interpolation="nearest", vmin=0, vmax=100 + ) # Create heatmap + plt.colorbar(heatmap) # Add a colorbar to indicate scale + plt.title("Dynamic Heatmap of Random Values") + + # Update the plot plt.draw() - plt.pause(1e-17) - -# add this if you don't want the window to disappear at the end + plt.pause(0.5) # Pause to see the update + +# Keep the plot window open at the end +plt.ioff() # Turn off interactive mode plt.show()