Skip to content

Commit 12165ec

Browse files
committed
updated
1 parent efbac56 commit 12165ec

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
speed,risk
2+
200,95
3+
90,20
4+
300,98
5+
110,60
6+
240,72
7+
115,10
8+
50,7
9+
230,85
10+
190,45
11+
260,91
12+
290,82
13+
185,59
14+
310,93
15+
95,18
16+
30,2

Visualization/csv_viewer.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import sys
2+
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QPushButton, QFileDialog, QWidget, QInputDialog
3+
import pandas as pd
4+
import matplotlib.pyplot as plt
5+
6+
class CSVViewerApp(QMainWindow):
7+
def __init__(self):
8+
super().__init__()
9+
self.initUI()
10+
11+
def initUI(self):
12+
self.setWindowTitle('CSV Viewer')
13+
self.setGeometry(100, 100, 800, 600)
14+
15+
layout = QVBoxLayout()
16+
17+
self.load_btn = QPushButton('Load CSV')
18+
self.load_btn.clicked.connect(self.load_csv)
19+
layout.addWidget(self.load_btn)
20+
21+
self.plot_btn = QPushButton('Plot Data')
22+
self.plot_btn.clicked.connect(self.show_plot_dialog)
23+
layout.addWidget(self.plot_btn)
24+
25+
self.central_widget = QWidget()
26+
self.central_widget.setLayout(layout)
27+
self.setCentralWidget(self.central_widget)
28+
29+
def load_csv(self):
30+
file_name, _ = QFileDialog.getOpenFileName(self, "Open CSV File", "", "CSV Files (*.csv);;All Files (*)")
31+
if file_name:
32+
self.df = pd.read_csv(file_name)
33+
34+
def plot_data(self, columns):
35+
if hasattr(self, 'df'):
36+
self.df[columns].plot(kind='bar')
37+
plt.title(f'CSV Data Visualization')
38+
plt.xlabel('X-axis Label')
39+
plt.ylabel('Y-axis Label')
40+
plt.legend(columns)
41+
plt.show()
42+
43+
def show_plot_dialog(self):
44+
if hasattr(self, 'df'):
45+
columns, ok = QInputDialog.getText(self, "Column Selection", "Enter the column names or indices (comma-separated) to plot:")
46+
if ok:
47+
try:
48+
column_indices = [int(idx) for idx in columns.split(",")]
49+
except ValueError:
50+
column_indices = columns.split(",")
51+
52+
selected_columns = []
53+
for idx in column_indices:
54+
if isinstance(idx, int):
55+
selected_columns.append(self.df.columns[idx])
56+
else:
57+
selected_columns.append(idx.strip())
58+
59+
valid_columns = [col for col in selected_columns if col in self.df.columns]
60+
61+
if valid_columns:
62+
self.plot_data(valid_columns)
63+
else:
64+
print("Invalid column names or indices.")
65+
66+
if __name__ == '__main__':
67+
app = QApplication(sys.argv)
68+
window = CSVViewerApp()
69+
window.show()
70+
sys.exit(app.exec())

0 commit comments

Comments
 (0)