【问题标题】:Rep-lit + Histograms + Matplotlib -- code works in Python but won't work on replit and there's no error messagesRep-lit + Histograms + Matplotlib -- 代码在 Python 中工作,但不能在 repli 上工作,并且没有错误消息
【发布时间】:2022-01-21 19:51:26
【问题描述】:

再次提出已结束的同一个问题:

我是一名大学教授,想在不让学生在计算机上安装 Python 的情况下教授 Python 课程。我正在使用我调整过的同事的这段代码。它在 Python 中工作。它引用两个带有坐标的 Excel 电子表格,并为每个电子表格生成直方图。

Replit 不会运行代码。当我单击“运行”时,它开始安装软件包,然后在某个时候停止。 没有错误消息,状态屏幕变为空白,只显示一个光标。我检查了我的存储库,没有新图像。我假设我在 Excel 导入 + 熊猫上做错了,或者我缺少在线运行 matplotlib 的设置。有人可以帮忙吗?

github 存储库有代码 + 2 个 excel 表。我绝对希望在 replit 上运行它,因为每个学生都在使用他们的个人计算机,而且对于一个入门级课程来说,让他们安装 Python 实在是太多了。

enter link description here

【问题讨论】:

标签: python excel pandas matplotlib repl.it


【解决方案1】:

修好了!

首先,我试图在不了解 replit 界面的情况下运行代码。我将它粘贴到 main.py 中

接下来,我必须安装 pip(使用他们的软件包界面安装),然后它就可以工作了

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")

【讨论】:

    猜你喜欢
    • 2016-05-22
    • 2014-09-30
    • 1970-01-01
    • 2017-12-11
    • 2016-03-10
    • 2017-06-05
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    相关资源
    最近更新 更多