在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参数或使用虚拟环境。