Bqplot: Ermöglichen von Python-basierten 2D-Visualisierungen ✊ | von Manoj Das | Juni 2023

0
101


Was ist Bqplot? Beispiel einer Datenvisualisierung mithilfe der Bqplot-Bibliothek. Einführung in das Bqplot-Paket in Python mit Beispielen.

Foto von Guilherme Stecanella An Unsplash

Bqplot ist eine Python-Plotbibliothek, die auf der interaktiven Visualisierungsbibliothek Plotly basiert. Es bietet eine Excessive-Stage-API zum Erstellen interaktiver und anpassbarer Visualisierungen in Jupyter-Notebooks und Webanwendungen. Mit Bqplot können wir mithilfe der Plotly.js-Bibliothek umfangreiche und interaktive Visualisierungen erstellen.

Bqplot bietet eine breite Palette an Diagrammtypen, darunter Liniendiagramme, Streudiagramme, Balkendiagramme, Histogramme, Heatmaps und mehr. Es bietet auch Unterstützung für Interaktivität wie Schwenken, Zoomen und Pinseln. Sie können komplexe Visualisierungen erstellen, indem Sie mehrere Diagramme und Widgets miteinander kombinieren.

Eines der Hauptmerkmale von Bqplot ist die Integration mit Jupyter-Notebooks. Damit können Sie interaktive Diagramme direkt in der Pocket book-Umgebung erstellen und so Daten effektiver untersuchen und analysieren. Bqplot unterstützt auch das Jupyter-Framework für interaktive Widgets, was bedeutet, dass Sie Plots und Widgets miteinander verknüpfen können, um dynamische Visualisierungen zu erstellen, die auf Benutzerinteraktionen reagieren.

Die Bibliothek wurde ursprünglich von Bloomberg LP entwickelt und erstmals im Jahr 2016 veröffentlicht. Die Motivation hinter der Entwicklung von Bqplot bestand darin, eine Plotbibliothek auf hohem Niveau bereitzustellen, die die Leistungsfähigkeit von Jupyter-Notebooks nutzt und es Benutzern ermöglicht, interaktive Visualisierungen direkt in der Pocket book-Umgebung zu erstellen .

Bqplot wurde vom Erfolg und der Popularität der D3.js-Bibliothek inspiriert, die leistungsstarke Instruments zum Erstellen von Datenvisualisierungen im Net bietet. Die Entwickler von Bqplot wollten Python-Benutzern eine ähnliche Interaktivität und Flexibilität bieten, wobei der Schwerpunkt auf der Integration mit Jupyter-Notebooks lag.

Die Bibliothek basiert auf Plotly, einer weit verbreiteten Open-Supply-Bibliothek zum Erstellen interaktiver Visualisierungen. Durch die Verwendung von Plotly als Backend ist Bqplot in der Lage, interaktive Visualisierungen zu generieren, die direkt in Jupyter-Notebooks angezeigt und bearbeitet werden können.

Bqplot bietet eine Reihe von Diagrammtypen, darunter Liniendiagramme, Streudiagramme, Balkendiagramme, Histogramme, Heatmaps und mehr. Es unterstützt auch Interaktivitätsfunktionen wie Schwenken, Zoomen und Bürsten, sodass Benutzer Daten effektiver erkunden und analysieren können.

Seit seiner ersten Veröffentlichung hat Bqplot bei Datenwissenschaftlern, Forschern und Entwicklern, die mit Jupyter-Notebooks arbeiten, an Popularität gewonnen. Die Bibliothek verfügt über eine wachsende Neighborhood und erhält weiterhin Updates und Verbesserungen.

Pip verwenden:

pip set up bqplot

Conda verwenden:

conda set up -c conda-forge bqplot

Wenn Sie JupyterLab <= 2 verwenden:

jupyter labextension set up @jupyter-widgets/jupyterlab-manager bqplot

Liniendiagramm

import bqplot.pyplot as plt
import numpy as np

# create information vectors x and y to plot utilizing a Strains mark
x = np.linspace(-10, 10, 100)
y = np.sin(x)

# 1. Create the determine object
fig = plt.determine(title="Line Chart")

# 2. By default axes are created with fundamental defaults. If you wish to customise the axes create
# a dict and move it to axes_options argument within the marks
axes_opts = {"x": {"label": "X"}, "y": {"label": "Y"}}

# 3. Create a Strains mark by calling plt.plot perform
line = plt.plot(
x=x, y=y, axes_options=axes_opts
) # word that customized axes choices are handed to the mark perform

# 4. Render the determine utilizing plt.present() (shows toolbar as effectively)
plt.present()

Liniendiagramm

Balkendiagramm

# first, create information vectors x and y to plot a bar chart
x = listing("ABCDE")
y = np.random.rand(5)

# 1. Create the determine object
fig = plt.determine(title="Bar Chart")

# 2. Customise the axes choices
axes_opts = {
"x": {"label": "X", "grid_lines": "none"},
"y": {"label": "Y", "tick_format": ".0%"},
}

# 3. Create a Bars mark by calling plt.bar perform
bar = plt.bar(x=x, y=y, padding=0.5, axes_options=axes_opts)

# 4. immediately show the determine object created in step 1 (word that the toolbar now not exhibits up)
fig

Balkendiagramm

Streudiagramm

# first, let's create two vectors x and y
x = np.linspace(-10, 10, 25)
y = 3 * x + 5
y_noise = y + 10 * np.random.randn(25) # add some random noise to y

# 1. Create the determine object
fig = plt.determine(title="Scatter and Line")

# 3. Create line and scatter marks
# extra attributes (stroke_width, colours and so forth.) may be handed as attributes
# to the mark objects as wanted
line = plt.plot(x=x, y=y, colours=["green"], stroke_width=3)
scatter = plt.scatter(x=x, y=y_noise, colours=["red"], stroke="black")

# setting x and y axis labels utilizing pyplot features. Observe that these features
# ought to be referred to as solely after creating the marks
plt.xlabel("X")
plt.ylabel("Y")

# 4. render the determine
fig

Streudiagramm

Weltkarte

import bqplot.pyplot as plt

fig = plt.determine(title="World Map")
plt.geo(map_data="WorldMap",
colours={"default_color": "steelblue"})
fig

Weltgrundkarte

Choropleth

fig = plt.determine(title="Choropleth")

plt.scales(scales={"coloration": bq.ColorScale(scheme="Greens")})
chloro_map = plt.geo(
map_data="WorldMap",
coloration={643: 105, 4: 21, 398: 23, 156: 42, 124: 78, 76: 98},
colours={"default_color": "Gray"},
)
fig

Choropleth unter Verwendung der Bqplot-Bibliothek

Erweiterte Projektionen

import bqplot as bq

fig = plt.determine(title="Superior World Map")
geo_scale = bq.Orthographic(scale_factor=375, middle=[0, 25], rotate=(-50, 0))
plt.scales(scales={"projection": geo_scale})
map_mark = plt.geo(
map_data="WorldMap",
colours={682: "inexperienced", 356: "crimson", 643: "blue", "default_color": "orange"},
)
fig

Erweiterte Weltkarte mit der Bqplot-Bibliothek

Alle weiteren Particulars und weitere Beispiele finden Sie hier Hier

Quelle

— — —

Warum wurde die Bqplot-Bibliothek zum Zauberer?

Weil es Daten auf magische Weise in fesselnde visuelle Illusionen verwandeln könnte!

🙂🙂🙂



Source link

HINTERLASSEN SIE EINE ANTWORT

Please enter your comment!
Please enter your name here