Ho tracciato con successo diversi set di dati e funzioni adattate utilizzando Bokeh, ma ho davvero bisogno di aggiungere barre di errore ai grafici, come potrei fare per farlo?Come aggiungete le barre di errore ai grafici Bokeh in python?
11
A
risposta
16
EDIT: Questo è ora integrato in Bokeh, consultare la documentazione:
https://bokeh.pydata.org/en/latest/docs/user_guide/annotations.html#whiskers
e
https://bokeh.pydata.org/en/latest/docs/user_guide/annotations.html#bands
Vedi https://stackoverflow.com/a/46517148/3406693 per un esempio completo.
Forse è un po 'tardi ma volevo farlo anche oggi.
È un peccato che il bokeh non offra questa funzione da solo.
import numpy as np
from bokeh.plotting import figure, show, output_file
# some pseudo data
xs = np.linspace(0, 2*np.pi, 25)
yerrs = np.random.uniform(0.1, 0.3, xs.shape)
ys = np.sin(xs) + np.random.normal(0, yerrs, xs.shape)
output_file('bokeh_errorbars.html')
# plot the points
p = figure(title='errorbars with bokeh', width=800, height=400)
p.xaxis.axis_label = 'x'
p.yaxis.axis_label = 'y'
p.circle(xs, ys, color='red', size=5, line_alpha=0)
# create the coordinates for the errorbars
err_xs = []
err_ys = []
for x, y, yerr in zip(xs, ys, yerrs):
err_xs.append((x, x))
err_ys.append((y - yerr, y + yerr))
# plot them
p.multi_line(err_xs, err_ys, color='red')
show(p)
E questo è il risultato:
Si potrebbe desiderare di usarlo come una funzione come questa:
def errorbar(fig, x, y, xerr=None, yerr=None, color='red',
point_kwargs={}, error_kwargs={}):
fig.circle(x, y, color=color, **point_kwargs)
if xerr:
x_err_x = []
x_err_y = []
for px, py, err in zip(x, y, xerr):
x_err_x.append((px - err, px + err))
x_err_y.append((py, py))
fig.multi_line(x_err_x, x_err_y, color=color, **error_kwargs)
if yerr:
y_err_x = []
y_err_y = []
for px, py, err in zip(x, y, yerr):
y_err_x.append((px, px))
y_err_y.append((py - err, py + err))
fig.multi_line(y_err_x, y_err_y, color=color, **error_kwargs)
Problemi correlati
- 1. Bar etichettati individualmente per grafici a barre in matplotlib/Python
- 2. Come faccio a lavorare con le immagini in bokeh (Python)
- 3. Le librerie di grafici o di diagrammi Web supportano barre di errore?
- 4. Grafici di controllo in Python
- 5. Crea grafici a bokeh con controlli interattivi in django
- 6. Come tracciare le barre di errore in coordinate polari in python?
- 7. Tracciare grafici con i nastri di errore in python
- 8. come disegnare in pila Grafici a barre in iOS
- 9. Timeseries streaming in bokeh
- 10. Barre sovrapposte per grafici a barre multiasse NVD3 su disegno
- 11. Come creare grafici a barre verticali rotti in matpltolib?
- 12. Due grafici a barre in matplotlib sovrapposti nel modo sbagliato
- 13. Hype attorno ai database di grafici ... perché?
- 14. Dare ai grafici un sottotitolo in matplotlib
- 15. Come mostrare i grafici matplotlib in python
- 16. R grafici: creazione delle linee di barre orizzontali di Tufte
- 17. due barre in Python
- 18. Come posso creare grafici a barre e grafici a torta in js angolari
- 19. Come aggiungere frecce ai grafici linea in Matlab?
- 20. Impedire ai ticklabell lunghi dell'asse X di essere tagliati in grafici a barre con trama in R
- 21. Creazione di grafici delle dipendenze in Python
- 22. Centratura etichette di testo su grafici a barre impilati
- 23. Aggiunta di barre di errore su un grafico a barre in gnuplot
- 24. Ordine in legenda grafici python
- 25. Larghezza delle barre di errore in ggplot2
- 26. Scopo di columnDataSource in bokeh
- 27. Come stampare grafici a barre con le stesse coordinate X affiancate
- 28. Bokeh scala logaritmica per bar chart
- 29. Disegno di grafici cluster in Python
- 30. Bootstrap: come abilitare le barre di scorrimento?