0

Reasking the same question that got closed:

I am a college professor who wants to teach a Python lesson without having students install Python on their computers. I am using this code from a colleague that I have tweaked. It works in Python. It is referencing two excel spreadsheets with coordinates and produces histograms for each.

Replit will not run the code. When I click "run" it begins installing the packages and then stops at some point. There are no error messages and the status screen goes blank, showing just a cursor. I checked my repository and there are no new images. I am assuming I am doing something wrong with either the Excel import + pandas or I am missing settings for running matplotlib online. Can someone help?

The github repository has the code + the 2 excel sheets. I absolutely want to run this on replit because each student is using their personal computer and it's too much for one introductory level class session to have them install Python.

enter link description here

Natalie
  • 1
  • 1

1 Answers1

0

Fixed it!

First, I was trying to run the code without understanding the replit interface. I pasted it into main.py

Next, I had to install pip (did so using their packages interface), and after that it worked

import pandas as pd
import matplotlib.pyplot as plt
import openpyxl as pip

# Import excel files with the X and Y coordinates for flake distributions
# x and y coordinates were created in QGIS and exported into an excel file
r_basalt = pd.ExcelFile("Basalt-Right.xlsx")  # x and y coordinates for flakes knapped by a right hander
l_basalt = pd.ExcelFile("Basalt-Left.xlsx")  # x and y coordinates for flakes knapped by a left hander
#Creating dataframes for Sheet 1 in left and right hander flake coordinates
df_right = r_basalt.parse("Sheet1")
df_left = l_basalt.parse ("Sheet1")
#Identifying individual X and Y columns and turning them into lists
#Right
right_x = df_right["x"].tolist()
right_y = df_right["y"].tolist()
#Left
left_x = df_left["x"].tolist()
left_y = df_left["y"].tolist()
# Create empty grid
S = 200 #dimension of grid, 200 square centimeters
N = 10 #dimension of the grid lines, 10 centimeters apart
#min and max from nail coordinates recorded by the total station
x_max = 101.517
x_min = 98.761
y_max = 100.000
y_min = 97.798
# Right Hander Plot
plt.hist2d(right_x, right_y, bins=S)
plt.colorbar()
plt.xlabel("x (meters)")
plt.ylabel("y (meters)")
plt.title("Right-Hander Flakes")
plt.savefig("rh.jpeg")
#clear the plot so as not to retain the color ramp on next graph
plt.clf()
# Left Hander Plot
plt.hist2d(left_x, left_y, bins=S)
plt.colorbar()
plt.xlabel("x (meters)")
plt.ylabel("y (meters)")
plt.title("Left-Hander Flakes")
plt.savefig("lh.jpeg")
Natalie
  • 1
  • 1