在Debian上進行Python數據可視化,可按以下步驟操作:
安裝基礎環境
sudo apt update && sudo apt install python3 python3-pip
安裝可視化庫
pip3 install matplotlib seaborn pandas numpy
(可選:plotly、bokeh等交互式庫)
基礎可視化示例
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y, label='sin(x)')
plt.xlabel('X軸')
plt.ylabel('Y軸')
plt.title('示例折線圖')
plt.legend()
plt.show()
import seaborn as sns
import pandas as pd
data = pd.DataFrame({'類別': ['A', 'B', 'C'], '值': [10, 20, 15]})
sns.barplot(x='類別', y='值', data=data)
plt.title('示例柱狀圖')
plt.show()
交互式可視化(可選)
import plotly.express as px
fig = px.scatter(x=[1, 2, 3], y=[4, 5, 6], title='交互式散點圖')
fig.show()
from bokeh.plotting import figure, show
p = figure(title='交互式圖表', x_axis_label='X', y_axis_label='Y')
p.circle([1, 2, 3], [4, 5, 6])
show(p)
進階工具
pip3 install pandas-profiling
from pandas_profiling import ProfileReport
profile = ProfileReport(df, title='數據報告')
profile.to_file('report.html')
說明:
pip3 install jupyterlab)實現交互式開發。--user參數或使用虛擬環境。