Bokeh – Parcelas Múltiples

Prerrequisitos: Introducción a Bokeh en Python 

En este artículo, discutiremos cómo trazar múltiples parcelas usando Bokeh en Python. Vamos a usar el método row() del módulo bokeh.layouts , se usa en el método show() de la biblioteca bokeh.io como argumento para representar múltiples gráficos al usar bokeh

Sintaxis:

mostrar(fila(fig1,fig2,fig3…..fign)) 

En el que fig1, fig2 , etc. son objetos de la clase figure en el módulo bokeh.plotting .

Acercarse

  • Importar módulos requeridos
  • Asigne coordenadas y represente parcelas utilizando la clase de figura .
  • Usa los objetos de figura como argumentos en el método row() .
  • Utilice el método show() para representar la visualización devuelta por el método row() .

 

Ejemplo 1:

Diferentes tramas en la misma página

Python3

# import modules
from bokeh.io import output_file, show
from bokeh.layouts import row
from bokeh.plotting import figure
 
# create a new plot
fig1 = figure(plot_width=500,
              plot_height=500)
fig1.line([1, 2, 3, 4, 5],
          [3, 1, 2, 6, 5],
          line_width=5)
 
# create another plot
x = y = list(range(10))
fig2 = figure(plot_width=500,
              plot_height=500)
fig2.circle(x, y, size=5)
 
# depict visualization
show(row(fig1, fig2))

Producción:

Ejemplo 2:

Diferentes parcelas en el mismo marco

Python3

# import modules
from bokeh.io import output_file, show
from bokeh.layouts import row
from bokeh.plotting import figure
import numpy as np
import random
 
 
# create a new plot
# instantiating the figure object
fig1 = figure(title="Plot 1")
 
# coordinates
x = [[[[0, 0, 1, 1]]],
     [[[2, 2, 4, 4], [2.5, 2.5, 3.5, 3.5]]],
     [[[2, 0, 4]]]]
y = [[[[2.5, 0.5, 0.5, 2.5]]],
     [[[1, 0, 0, 1], [0.75, 0.25, 0.25, 0.75]]],
     [[[2, 0, 0]]]]
 
# color values of the polygons
color = ["red", "purple", "yellow"]
 
# fill alpha values of the polygons
fill_alpha = 0.5
 
# plotting the graph
fig1.multi_polygons(x, y,
                    color=color,
                    fill_alpha=fill_alpha)
 
 
# create another plot
# coordinates
x = np.arange(5)
y = x**2
z = x*3
p = np.linspace(1, 20, 7)
q = np.linspace(1, 10, 7)
r = np.linspace(1, 30, 5)
a = np.arange(31)
 
# creating an empty figure with specific plot
# width and height
fig2 = figure(title="Plot 2")
 
# plotting the points in the form of
# circular glyphs
fig2.circle(x, y, color="red", size=20)
 
# plotting the points in the form of
# square glyphs
fig2.square(x, z, color="blue", size=15, alpha=0.5)
 
# plotting the points in the form of
# hex glyphs
fig2.hex(y, z, color="green", size=10, alpha=0.7)
 
# drawing a line between the plotted points
fig2.line(x, y, color="green", line_width=4)
 
# plotting the points in the form of
# inverted triangle glyph
fig2.inverted_triangle(p, q, color="yellow", size=20, alpha=0.4)
 
# plotting the points in the form of
# diamond glyphs
fig2.diamond(x, r, color="purple", size=16, alpha=0.8)
 
# plotting the points in the form of
# cross glyphs
fig2.cross(a, a, size=14)
 
 
# create a third plot
# generating the points to be plotted
x = []
y = []
for i in range(100):
    x.append(i)
for i in range(100):
    y.append(1 + random.random())
 
# parameters of line 1
line_color = "red"
line_dash = "solid"
legend_label = "Line 1"
 
fig3 = figure(title="Plot 3")
 
# plotting the line
fig3.line(x, y,
          line_color=line_color,
          line_dash=line_dash,
          legend_label=legend_label)
 
# plotting line 2
# generating the points to be plotted
x = []
y = []
for i in range(100):
    x.append(i)
for i in range(100):
    y.append(random.random())
 
# parameters of line 2
line_color = "green"
line_dash = "dotdash"
line_dash_offset = 1
legend_label = "Line 2"
 
# plotting the line
fig3.line(x, y,
          line_color=line_color,
          line_dash=line_dash,
          line_dash_offset=line_dash_offset,
          legend_label=legend_label)
 
# depict visualization
show(row(fig1, fig2, fig3))

Producción:

Ejemplo 3: 

Múltiples parcelas seguidas

Python3

# import modules
from bokeh.io import output_file, show
from bokeh.layouts import row
from bokeh.plotting import figure
 
# assign coordinates
x = y = list(range(10))
xs = [[[[0, 0, 1, 1]]]]
ys = [[[[3, 2, 2, 3]]]]
 
# create a new plot
fig1 = figure(title="Plot 1", plot_width=250,
              plot_height=250)
fig1.line(x, y, line_width=25, color="lime")
 
# create another plot
fig2 = figure(title="Plot 2", plot_width=250,
              plot_height=250)
fig2.circle(x, y, size=25, color="lime")
 
# create another plot
fig3 = figure(title="Plot 3", plot_width=250,
              plot_height=250)
fig3.square(x, y, size=25, color="lime")
 
# create another plot
fig4 = figure(title="Plot 4", plot_width=250,
              plot_height=250)
fig4.triangle(x, y, size=25, color="lime")
 
# create another plot
fig5 = figure(title="Plot 5", plot_width=250,
              plot_height=250)
fig5.multi_polygons(xs, ys, color="lime")
 
# create another plot
fig6 = figure(title="Plot 6", plot_width=250,
              plot_height=250)
fig6.line(x, y, line_dash="dotted", color="lime")
 
# depict visualization
show(row(fig1, fig2,
         fig3, fig4,
         fig5, fig6))

Producción:

Publicación traducida automáticamente

Artículo escrito por riturajsaha y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *