在Python中,有許多庫(kù)可以用來(lái)創(chuàng)建交互式數(shù)據(jù)可視化。以下是一些建議:
import plotly.express as px
import pandas as pd
data = pd.read_csv("your_data.csv")
fig = px.scatter(data, x="x_column", y="y_column")
fig.show()
from bokeh.plotting import figure, show, output_file
from bokeh.io import output_notebook
import pandas as pd
data = pd.read_csv("your_data.csv")
p = figure(title="Interactive Plot", x_axis_label="x_column", y_axis_label="y_column")
p.circle(data["x_column"], data["y_column"])
show(p)
import matplotlib.pyplot as plt
import mplcursors
import pandas as pd
data = pd.read_csv("your_data.csv")
fig, ax = plt.subplots()
scatter = ax.scatter(data["x_column"], data["y_column"])
labels = data.columns
mplcursors.cursor(scatter, hover=True).connect("add", lambda sel: sel.annotation.set_text(labels[sel.target.index]))
plt.show()
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
data = pd.read_csv("your_data.csv")
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Dropdown(id="dropdown", options=[{"label": col, "value": col} for col in data.columns]),
dcc.Graph(id="graph")
])
@app.callback(
Output("graph", "figure"),
[Input("dropdown", "value")]
)
def update_graph(selected_column):
fig = px.scatter(data, x="x_column", y=selected_column)
return fig
if __name__ == "__main__":
app.run_server(debug=True)
這些庫(kù)和框架可以幫助你創(chuàng)建具有交互性的Python數(shù)據(jù)可視化。你可以根據(jù)項(xiàng)目需求和個(gè)人喜好選擇合適的工具。