3b1b / 3b1b/manim

Unexpected error when plotting data points

未關閉
#948 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
93.9k
分支
7.7k
平均合併
2 天 13 小時
30 天內合併 PR
4

描述

Trying to plot some data points using sublime text and I get this error. Any help would be appreciated.

Command ran:
```
from manimlib.imports import *

#Function to return data from .csv file to an array

def get_coords_from_csv(coronavirus_data):
import csv
coords = []
with open(f'coronavirus_data.csv', 'r') as csvFile:
reader = csv.reader(csvFile)
for row in reader:
x,y = row
coord = [float(x),float(y)]
coords.append(coord)
csvFile.close()
return coords

class GraphFromData(GraphScene):
def get_points_from_coords(self,coords):
return[
self.coords_to_point(px,py)
for px,py in coords
]

def get_dots_from_coords(self, coords, radius=0.1):
points = self.get_points_from_coords(coords)
dots = VGroup(*[
Dot(radius=radius).move_to([px,py,pz])
for px,py,pz in points
]
)
return dots

class DiscreteGraphFromSetPoints(VMobject):
def __init__(self, set_of_points, **kwargs):
super().__init__(**kwargs)
self.set_points_as_corners(set_of_points)

class SmoothGraphFromSetPoints(VMobject):
def __init__(self, set_of_points, **kwargs):
super().__init__(**kwargs)
self.set_points_smoothly(set_of_points)

#Graph with set of points
class CustomGraph1(GraphFromData):
def construct(self):
self.setup_axes()
coords = get_coords_from_csv("coronavirus_data")
dots = self.get_dots_from_coords(coords)
self.add(dots)
```

The error:
Traceback (most recent call last):
File "/Users/lewis/Documents/animation/manim/manimlib/extract_scene.py", line 155, in main
scene = SceneClass(**scene_kwargs)
File "/Users/lewis/Documents/animation/manim/manimlib/scene/scene.py", line 53, in __init__
self.construct()
File "coronavirus.py", line 49, in construct
coords = get_coords_from_csv("coronavirus_data")
File "coronavirus.py", line 13, in get_coords_from_csv
coord = [float(x),float(y)]
ValueError: could not convert string to float: '\ufeff1'

Many thanks :)

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

該錯誤發生在讀取包含 BOM 字符的 CSV 檔案時的 get_coords_from_csv 中。問題在於將字串轉為 float 的那一行。檢查 CSV 檔案格式和 csv 模組的使用方式。修復可能涉及處理或移除檔案中的 BOM(byte order mark)。檢查 manimlib 程式碼中的類似 CSV 處理方式或查看 GraphScene 類別。使用範例 CSV 執行提供的腳本以重現此錯誤。

由索引模型根據 Issue 內容生成。

評估

領域
data-visualization
Issue 類型
缺陷
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
描述清楚
新手友好度
40/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。