在Linux环境下使用Python进行数据可视化有多种强大的工具和库可供选择。以下是一些主要的方案和工具:
pip install matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()
pip install seaborn
import seaborn as sns
tips = sns.load_dataset("tips")
sns.relplot(data=tips, x="total_bill", y="tip", hue="smoker")
pip install plotly
import plotly.express as px
fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
fig.show()
pip install bokeh
from bokeh.plotting import figure, show
p = figure(title="Basic Line Plot", x_axis_label='x', y_axis_label='y')
p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2)
show(p)
plt.show()
会弹出窗口显示图表plt.savefig('plot.png') # 支持PNG, PDF, SVG等格式
pip install jupyterlab
jupyter lab
pip install dash
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
dcc.Graph(
figure={
'data': [{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar'}]
}
)
])
app.run_server(debug=True)
pip install termgraph
echo "A 10\nB 20\nC 15" | termgraph
pip install plotext
import plotext as plt
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.show()
pip install mayavi
from mayavi import mlab
mlab.test_contour3d()
mlab.show()
pip install pyvista
import pyvista as pv
sphere = pv.Sphere()
sphere.plot()
在Linux环境下,这些工具都能良好运行,只需确保安装了必要的依赖库(如tkinter等GUI后端)。对于服务器环境,可以考虑使用X11转发或保存为图像文件的方式查看可视化结果。