Here are the examples of the python api bokeh.models.plots.Plot taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
13 Examples
3
Source : test_export.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_get_screenshot_as_png():
layout = Plot(x_range=Range1d(), y_range=Range1d(),
plot_height=20, plot_width=20, toolbar_location=None,
outline_line_color=None, background_fill_color=None,
border_fill_color=None)
png = bie.get_screenshot_as_png(layout)
assert png.size == (20, 20)
# a 20x20px image of transparent pixels
assert png.tobytes() == ("\x00"*1600).encode()
@pytest.mark.unit
3
Source : test_export.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_get_screenshot_as_png_with_driver(webdriver):
layout = Plot(x_range=Range1d(), y_range=Range1d(),
plot_height=20, plot_width=20, toolbar_location=None,
outline_line_color=None, background_fill_color=None,
border_fill_color=None)
png = bie.get_screenshot_as_png(layout, driver=webdriver)
assert png.size == (20, 20)
# a 20x20px image of transparent pixels
assert png.tobytes() == ("\x00"*1600).encode()
@pytest.mark.unit
3
Source : test_export.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_get_screenshot_as_png_large_plot(webdriver):
layout = Plot(x_range=Range1d(), y_range=Range1d(),
plot_height=800, plot_width=800, toolbar_location=None,
outline_line_color=None, background_fill_color=None,
border_fill_color=None)
bie.get_screenshot_as_png(layout, driver=webdriver)
# LC: Although the window size doesn't match the plot dimensions (unclear
# why), the window resize allows for the whole plot to be captured
assert webdriver.get_window_size() == {'width': 1366, 'height': 768}
@pytest.mark.unit
3
Source : test_export.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_get_svgs_no_svg_present():
layout = Plot(x_range=Range1d(), y_range=Range1d(),
plot_height=20, plot_width=20, toolbar_location=None)
svgs = bie.get_svgs(layout)
assert svgs == []
@pytest.mark.unit
3
Source : test_export.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_get_layout_html_resets_plot_dims():
initial_height, initial_width = 200, 250
layout = Plot(x_range=Range1d(), y_range=Range1d(),
plot_height=initial_height, plot_width=initial_width)
bie.get_layout_html(layout, height=100, width=100)
assert layout.plot_height == initial_height
assert layout.plot_width == initial_width
def test_layout_html_on_child_first():
3
Source : test_export.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_layout_html_on_child_first():
p = Plot(x_range=Range1d(), y_range=Range1d())
bie.get_layout_html(p, height=100, width=100)
layout = row(p)
bie.get_layout_html(layout)
def test_layout_html_on_parent_first():
3
Source : test_export.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_layout_html_on_parent_first():
p = Plot(x_range=Range1d(), y_range=Range1d())
layout = row(p)
bie.get_layout_html(layout)
bie.get_layout_html(p, height=100, width=100)
#-----------------------------------------------------------------------------
# Private API
#-----------------------------------------------------------------------------
@patch('PIL.Image.Image')
3
Source : test_saving.py
with MIT License
from rthorst
with MIT License
from rthorst
def test__save_helper(mock_file_html, mock_io_open):
obj = Plot()
filename, resources, title = bis._get_save_args(curstate(), "filename", "resources", "title")
bis._save_helper(obj, filename, resources, title, None)
assert mock_file_html.call_count == 1
assert mock_file_html.call_args[0] == (obj, resources)
assert mock_file_html.call_args[1] == dict(title="title", template=None)
assert mock_io_open.call_count == 1
assert mock_io_open.call_args[0] == (filename,)
assert mock_io_open.call_args[1] == dict(mode="w", encoding="utf-8")
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
3
Source : test_showing.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_show_with_default_args(mock__show_with_state):
curstate().reset()
default_kwargs = dict(browser=None, new="tab", notebook_handle=False)
p = Plot()
bis.show(p, **default_kwargs)
assert mock__show_with_state.call_count == 1
assert mock__show_with_state.call_args[0] == (p, curstate(), None, "tab")
assert mock__show_with_state.call_args[1] == {'notebook_handle': False}
assert curdoc().roots == []
@patch('bokeh.io.showing._show_with_state')
3
Source : test_showing.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_show_with_explicit_args(mock__show_with_state):
curstate().reset()
kwargs = dict(browser="browser", new="new", notebook_handle=True)
p = Plot()
bis.show(p, **kwargs)
assert mock__show_with_state.call_count == 1
assert mock__show_with_state.call_args[0] == (p, curstate(), "browser", "new")
assert mock__show_with_state.call_args[1] == {'notebook_handle': True}
assert curdoc().roots == []
@patch('bokeh.io.showing.run_notebook_hook')
3
Source : test_showing.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_show_doesn_not_adds_obj_to_curdoc(m):
curstate().reset()
assert curstate().document.roots == []
p = Plot()
bis.show(p)
assert curstate().document.roots == []
p = Plot()
bis.show(p)
assert curstate().document.roots == []
@pytest.mark.parametrize('obj', [1, 2.3, None, "str", GlyphRenderer()])
0
Source : test_export.py
with MIT License
from rthorst
with MIT License
from rthorst
def test_get_svgs_with_svg_present(webdriver):
def fix_ids(svg):
svg = re.sub(r'id="\w{12}"', 'id="X"', svg)
svg = re.sub(r'url\(#\w{12}\)', 'url(#X)', svg)
return svg
layout = Plot(x_range=Range1d(), y_range=Range1d(),
plot_height=20, plot_width=20, toolbar_location=None,
outline_line_color=None, border_fill_color=None,
background_fill_color="red", output_backend="svg")
svg0 = fix_ids(bie.get_svgs(layout, driver=webdriver)[0])
svg1 = fix_ids(bie.get_svgs(layout, driver=webdriver)[0])
svg2 = (
' < svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" '
'width="20" height="20" style="width: 20px; height: 20px;">'
' < defs/>'
' < g>'
' < g transform="scale(1,1) translate(0.5,0.5)">'
' < rect fill="#FFFFFF" stroke="none" x="0" y="0" width="20" height="20"/>'
' < rect fill="red" stroke="none" x="5" y="5" width="10" height="10"/>'
' < g/>'
' < /g>'
' < /g>'
' < /svg>'
)
assert svg0 == svg2
assert svg1 == svg2
def test_get_layout_html_resets_plot_dims():
0
Source : test_showing.py
with MIT License
from rthorst
with MIT License
from rthorst
def test__show_with_state_with_notebook(mock_get_browser_controller,
mock__show_file_with_state,
mock_run_notebook_hook):
mock_get_browser_controller.return_value = "controller"
s = State()
p = Plot()
s.output_notebook()
bis._show_with_state(p, s, "browser", "new")
assert s.notebook_type == "jupyter"
assert mock_run_notebook_hook.call_count == 1
assert mock_run_notebook_hook.call_args[0] == ("jupyter", "doc", p, s, False)
assert mock_run_notebook_hook.call_args[1] == {}
assert mock__show_file_with_state.call_count == 0
s.output_file("foo.html")
bis._show_with_state(p, s, "browser", "new")
assert s.notebook_type == "jupyter"
assert mock_run_notebook_hook.call_count == 2
assert mock_run_notebook_hook.call_args[0] == ("jupyter", "doc", p, s, False)
assert mock_run_notebook_hook.call_args[1] == {}
assert mock__show_file_with_state.call_count == 1
assert mock__show_file_with_state.call_args[0] == (p, s, "new", "controller")
assert mock__show_file_with_state.call_args[1] == {}
@patch('bokeh.io.notebook.get_comms')