簡體   English   中英

Rep-lit + Histograms + Matplotlib - 代碼在 Python 中有效,但不適用於 repli 並且沒有錯誤消息

[英]Rep-lit + Histograms + Matplotlib -- code works in Python but won't work on replit and there's no error messages

重新提出已關閉的相同問題:

我是一名大學教授,他想教授 Python 課程,而不讓學生在他們的計算機上安裝 Python。 我正在使用我調整過的同事的這段代碼。 它適用於 Python。 它引用了兩個帶有坐標的 excel 電子表格,並為每個電子表格生成直方圖。

Repli 不會運行代碼。 當我單擊“運行”時,它開始安裝軟件包,然后在某個時候停止。 沒有錯誤消息,狀態屏幕變為空白,僅顯示 cursor。 我檢查了我的存儲庫,沒有新圖像。 我假設我在 Excel 導入 + pandas 上做錯了,或者我缺少在線運行 matplotlib 的設置。 有人可以幫忙嗎?

github 存儲庫具有代碼 + 2 張 excel 表。 我絕對想在replit上運行這個,因為每個學生都在使用他們的個人電腦,對於一個入門級class session來說太多了讓他們安裝ZA7F5F35426B927411FC9231B563827。

在此處輸入鏈接描述

解決它!

首先,我試圖在不了解 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")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM