在Python中,可以使用多個庫進行數據可視化,以下是一些常用的庫及其基本用法:
在使用這些庫進行數據可視化時,通常需要先準備好數據,然后使用相應的函數或方法創建圖表。以下是一些基本示例:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
plt.xlabel('X軸')
plt.ylabel('Y軸')
plt.title('折線圖')
plt.show()
import seaborn as sns
data = sns.load_dataset('tips')
sns.boxplot(x='day', y='total_bill', data=data)
plt.show()
import plotly.express as px
data = px.data.iris()
fig = px.scatter(data, x='sepal_width', y='sepal_length', color='species')
fig.show()
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource
data = {'x': [1, 2, 3, 4, 5], 'y': [6, 7, 2, 4, 5]}
source = ColumnDataSource(data)
p = figure(x_axis_label='X軸', y_axis_label='Y軸')
p.vbar(x='x', top='y', source=source)
show(p)
以上是一些基本示例,實際上這些庫都提供了非常豐富的功能和選項,可以根據具體需求進行定制和擴展。