Skip to content

Commit

Permalink
Change the graph for better visualization (#23)
Browse files Browse the repository at this point in the history
* Change the graph for better visualization

* Changed the graph

---------

Co-authored-by: Tanisha Lalwani <[email protected]>
  • Loading branch information
Ananya-vastare and tanishaness authored Oct 8, 2024
1 parent 9de5f2c commit ca02b23
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions Backend/graph.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit ca02b23

Please sign in to comment.