Ich erstelle eine Figur in einer Funktion, z.
import numpy
from bokeh.plotting import figure, show, output_notebook
output_notebook()
def make_fig():
rows = cols = 16
img = numpy.ones((rows, cols), dtype=numpy.uint32)
view = img.view(dtype=numpy.uint8).reshape((rows, cols, 4))
view[:, :, 0] = numpy.arange(256)
view[:, :, 1] = 265 - numpy.arange(256)
fig = figure(x_range=[0, c], y_range=[0, rows])
fig.image_rgba(image=[img], x=[0], y=[0], dw=[cols], dh=[rows])
return fig
Später möchte ich die Figur näher betrachten:
fig = make_fig()
# <- zoom in on plot, like `set_xlim` from matplotlib
show(fig)
Wie kann ich programmatisch im Bokeh zoomen?
Eine Möglichkeit ist, Dinge mit einem einfachen Tupel zu machen, wenn Sie eine Figur erstellen:
figure(..., x_range=(left, right), y_range=(bottom, top))
Sie können aber auch die x_range
- und y_range
-Eigenschaften einer erstellten Figur direkt festlegen. (Ich hatte etwas wie set_xlim
oder set_ylim
von matplotlib gesucht.)
from bokeh.models import Range1d
fig = make_fig()
left, right, bottom, top = 3, 9, 4, 10
fig.x_range=Range1d(left, right)
fig.y_range=Range1d(bottom, top)
show(fig)
Vielleicht eine naive Lösung, aber warum nicht die Lim-Achse als Argument Ihrer Funktion übergeben?
import numpy
from bokeh.plotting import figure, show, output_notebook
output_notebook()
def make_fig(rows=16, cols=16,x_range=[0, 16], y_range=[0, 16], plot_width=500, plot_height=500):
img = numpy.ones((rows, cols), dtype=numpy.uint32)
view = img.view(dtype=numpy.uint8).reshape((rows, cols, 4))
view[:, :, 0] = numpy.arange(256)
view[:, :, 1] = 265 - numpy.arange(256)
fig = figure(x_range=x_range, y_range=y_range, plot_width=plot_width, plot_height=plot_height)
fig.image_rgba(image=[img], x=[0], y=[0], dw=[cols], dh=[rows])
return fig
sie können es auch direkt verwenden
p = Histogram(wind , xlabel= 'meters/sec', ylabel = 'Density',bins=12,x_range=Range1d(2, 16))
show(p)