Home »
MCQs
Bokeh MCQs (Multiple-Choice Questions)
Bokeh is a Python library for creating interactive and browser-based data visualizations. It provides tools for building interactive plots, dashboards, widgets, layouts, and web applications with support for JavaScript-based interactions and Bokeh Server applications.
Bokeh MCQs
These Bokeh multiple-choice questions cover important concepts such as figures, glyphs, data sources, interactive tools, layouts, widgets, callbacks, Bokeh Server, output formats, and plot customization. Practice these Bokeh MCQs to test and improve your knowledge of interactive data visualization with Python.
List of Bokeh MCQs
Here is a list of commonly asked Bokeh MCQs with answers and explanations.
1. What is Bokeh?
- A Python web browser
- A Python library for interactive data visualization
- A database management system
- A Python compiler
Answer: B) A Python library for interactive data visualization
Explanation:
Bokeh is a Python visualization library designed for creating interactive visualizations that can be displayed in web browsers.
2. Which Python module provides the figure() function in Bokeh?
bokeh.plotting
bokeh.graphics
bokeh.chart
bokeh.visual
Answer: A) bokeh.plotting
Explanation:
The figure() function is commonly imported from bokeh.plotting to create a new Bokeh plot.
3. Which statement correctly imports the Bokeh figure function?
from bokeh.plotting import figure
import figure from bokeh
from bokeh.figure import plotting
import bokeh.figure()
Answer: A) from bokeh.plotting import figure
Explanation:
The figure function is provided by the bokeh.plotting interface.
4. Which function is commonly used to display a Bokeh plot?
display()
show()
render()
view()
Answer: B) show()
Explanation:
The show() function from bokeh.io or bokeh.plotting is commonly used to display a Bokeh visualization.
5. What is a glyph in Bokeh?
- A database record
- A visual representation of data on a plot
- A Python package
- A web server
Answer: B) A visual representation of data on a plot
Explanation:
Glyphs are visual elements used to represent data in Bokeh. Examples include circles, lines, rectangles, bars, patches, and segments.
6. Which glyph is commonly used to represent individual data points?
- Circle
- Rectangle
- Patch
- Line
Answer: A) Circle
Explanation:
Circle or scatter glyphs can be used to represent individual observations as points on a Bokeh plot.
7. Which method can be used to create a line glyph?
line()
draw_line()
plot_line()
create_line()
Answer: A) line()
Explanation:
A Bokeh figure provides glyph methods such as line() for rendering line-based visualizations.
8. Which Bokeh glyph is commonly used for bar charts?
vbar()
barplot()
columnplot()
bar_chart()
Answer: A) vbar()
Explanation:
The vbar() glyph creates vertically oriented bars. Bokeh also provides hbar() for horizontal bars.
9. Which glyph is used to create horizontal bars?
horizontal_bar()
hbar()
barh()
horizontal()
Answer: B) hbar()
Explanation:
The hbar() glyph is used to create horizontally oriented bars in Bokeh.
10. Which object is Bokeh's fundamental data structure for many plots and data tables?
ColumnDataSource
DataFrameSource
PlotData
BokehData
Answer: A) ColumnDataSource
Explanation:
ColumnDataSource is a central Bokeh data structure that maps column names to sequences or arrays and can drive plots and other components.
11. From which module can ColumnDataSource be imported?
bokeh.models
bokeh.data
bokeh.source
bokeh.plotting.data
Answer: A) bokeh.models
Explanation:
ColumnDataSource is available from bokeh.models.
12. Which Python object can be directly used to initialize a ColumnDataSource?
- Dictionary
- Pandas DataFrame
- Both A and B
- Only a string
Answer: C) Both A and B
Explanation:
A ColumnDataSource can be initialized using a dictionary containing column data or a Pandas DataFrame, among other supported inputs.
13. What does each column in a ColumnDataSource represent?
- A sequence of values
- A plot title
- A toolbar
- A callback function
Answer: A) A sequence of values
Explanation:
A ColumnDataSource maps column names to sequences or arrays. Glyphs can refer to these columns when rendering data.
14. What requirement applies to the columns in a ColumnDataSource?
- All columns must have the same number of entries
- All columns must contain strings
- All columns must contain integers
- All columns must have unique values
Answer: A) All columns must have the same number of entries
Explanation:
Columns in a ColumnDataSource represent rows of related data, so the columns are expected to have matching lengths.
15. Which Bokeh method can be used to update selected values in a ColumnDataSource without replacing the entire dataset?
patch()
modify()
change_rows()
update_rows()
Answer: A) patch()
Explanation:
The patch() method can update specific locations in columns of a ColumnDataSource.
16. Which ColumnDataSource method is designed to add new data to an existing source?
stream()
append()
add()
push()
Answer: A) stream()
Explanation:
The stream() method is used to add new rows of data to a ColumnDataSource, making it useful for streaming or continuously updated visualizations.
17. Which module contains Bokeh layout functions such as row() and column()?
bokeh.layouts
bokeh.structure
bokeh.ui
bokeh.containers
Answer: A) bokeh.layouts
Explanation:
The bokeh.layouts module provides functions for arranging plots and widgets into layouts.
18. What does the row() layout generally do?
- Places components horizontally
- Places components vertically
- Deletes components
- Converts plots into tables
Answer: A) Places components horizontally
Explanation:
The row() layout arranges Bokeh components horizontally.
19. What does the column() layout generally do?
- Places components horizontally
- Places components vertically
- Creates a database column
- Creates a data source
Answer: B) Places components vertically
Explanation:
The column() layout arranges components vertically.
20. Which layout function can be used to arrange components in a grid-like structure?
gridplot()
grid()
tableplot()
matrixplot()
Answer: A) gridplot()
Explanation:
gridplot() is used to arrange multiple Bokeh plots in a grid layout.
21. Which Bokeh tool allows users to display information when hovering over glyphs?
- HoverTool
- InfoTool
- DisplayTool
- PointerTool
Answer: A) HoverTool
Explanation:
HoverTool provides tooltips and hover interactions for glyphs.
22. Which tool is commonly used to zoom into a Bokeh plot using a rectangular selection?
- BoxZoomTool
- RectangleTool
- AreaZoomTool
- SquareZoomTool
Answer: A) BoxZoomTool
Explanation:
BoxZoomTool allows users to select a rectangular region and zoom the plot to that region.
23. Which tool allows users to move or pan around a Bokeh plot?
- PanTool
- MoveTool
- DragTool
- ShiftTool
Answer: A) PanTool
Explanation:
PanTool allows users to move the visible range of a plot interactively.
24. Which tool restores a plot to its original range?
- ResetTool
- RestoreTool
- OriginalTool
- HomeTool
Answer: A) ResetTool
Explanation:
The ResetTool restores the plot ranges to their initial state.
25. Which Bokeh tool can be used to select individual data points?
- TapTool
- PointTool
- SelectPointTool
- ClickTool
Answer: A) TapTool
Explanation:
TapTool supports selection of glyphs by clicking or tapping them.
26. Which Bokeh object is used to create interactive controls such as sliders?
- Widget
- Controller
- InputObject
- ControlPanel
Answer: A) Widget
Explanation:
Bokeh provides widgets such as sliders, buttons, selectors, date pickers, and switches for creating interactive user interfaces.
27. Which Bokeh widget allows a user to select a value from a range?
- Slider
- RangeBox
- ValueSelector
- RangeWidget
Answer: A) Slider
Explanation:
The Slider widget allows users to select a numeric value between specified limits.
28. Which widget provides a list of choices that users can select from?
- Select
- ChoiceList
- OptionBox
- ListInput
Answer: A) Select
Explanation:
The Bokeh Select widget provides a dropdown-style interface for choosing an option.
29. Which widget provides a simple on/off control?
- Switch
- ToggleButton
- OnOff
- BooleanInput
Answer: A) Switch
Explanation:
The Switch widget provides an on/off toggle interface.
30. Which Bokeh class is used to provide JavaScript callbacks?
- CustomJS
- JavaScriptCallback
- JSFunction
- BrowserCallback
Answer: A) CustomJS
Explanation:
CustomJS allows JavaScript code to execute in the browser in response to Bokeh model changes or events.
31. Where does a CustomJS callback execute?
- In the browser's JavaScript environment
- Only inside a database
- Inside the Python compiler
- Inside the operating system kernel
Answer: A) In the browser's JavaScript environment
Explanation:
A CustomJS callback executes JavaScript in the browser. It does not directly execute Python code.
32. Which method can attach a CustomJS callback to a property change?
js_on_change()
on_js_change()
attach_js()
callback_js()
Answer: A) js_on_change()
Explanation:
The js_on_change() method attaches JavaScript callbacks to Bokeh model property changes or supported events.
33. Which method can attach a callback to a specific Bokeh event such as a tap?
js_on_event()
on_event_js()
event_callback()
attach_event()
Answer: A) js_on_event()
Explanation:
js_on_event() can associate a CustomJS callback with Bokeh events such as tap interactions.
34. Which method provides a convenient way to link one Bokeh model property to another?
js_link()
link_property()
bind_property()
connect_property()
Answer: A) js_link()
Explanation:
js_link() provides a convenient way to link one Bokeh model property to another using JavaScript-side behavior.
35. What is the primary purpose of Bokeh Server?
- To provide interactive applications with server-side Python callbacks
- To compile Python into machine code
- To store images permanently
- To replace web browsers
Answer: A) To provide interactive applications with server-side Python callbacks
Explanation:
Bokeh Server allows Bokeh applications to communicate with Python code on the server, enabling richer interactions and Python callbacks.
36. Which command is commonly used to run a Bokeh application from the command line?
bokeh serve
bokeh start
bokeh runserver
bokeh application
Answer: A) bokeh serve
Explanation:
The bokeh serve command is used to run Bokeh applications through the Bokeh Server.
37. Which function provides access to the current Bokeh document in a server application?
curdoc()
current_document()
getdoc()
document()
Answer: A) curdoc()
Explanation:
The curdoc() function returns the current Bokeh document, which is commonly used when building Bokeh Server applications.
38. Which function is used to create a static HTML output file for a Bokeh visualization?
output_file()
html_output()
save_html()
create_html()
Answer: A) output_file()
Explanation:
output_file() configures Bokeh to generate an HTML file when the visualization is shown or saved.
39. Which function can save a Bokeh model to an output file?
save()
store()
write_plot()
export_plot()
Answer: A) save()
Explanation:
The Bokeh save() function can save a Bokeh model as an output document, such as an HTML document.
40. Which function can be used to generate a complete HTML page containing a standalone Bokeh document?
file_html()
html_page()
create_html()
standalone_html()
Answer: A) file_html()
Explanation:
file_html() can generate a complete HTML document containing a standalone Bokeh document.
41. Which Bokeh class is used to create a table for displaying tabular data?
- DataTable
- DataGrid
- TableView
- DataFrameTable
Answer: A) DataTable
Explanation:
DataTable is a Bokeh widget used to display tabular data and can be connected to a ColumnDataSource.
42. Which Bokeh object is used to define columns in a DataTable?
- TableColumn
- DataColumn
- ColumnDefinition
- TableField
Answer: A) TableColumn
Explanation:
TableColumn defines how a column from the data source should be represented in a Bokeh DataTable.
43. Which property can be used to specify the width of a Bokeh plot?
width
plot_width_only
canvas_width
size_width
Answer: A) width
Explanation:
Bokeh plots have width and height properties that control the dimensions of the plot.
44. Which Bokeh property can be used to control responsive sizing?
sizing_mode
responsive
auto_size_mode
screen_mode
Answer: A) sizing_mode
Explanation:
The sizing_mode property controls how a Bokeh layout or plot adjusts its size relative to available space.
45. Which property can be used to set the title of a Bokeh plot?
title
plot_title_text
heading
caption
Answer: A) title
Explanation:
The title property represents the title of a Bokeh plot and can be customized through the plot's title object.
46. Which method can be used to select Bokeh models from a plot?
select()
find()
query()
locate()
Answer: A) select()
Explanation:
The select() method can be used to query Bokeh models based on criteria such as type or name.
47. Which function can export a Bokeh plot as a PNG image?
export_png()
save_png()
plot_to_png()
png_export()
Answer: A) export_png()
Explanation:
Bokeh provides export_png() for exporting plots or layouts as PNG images. Image export requires the appropriate browser automation dependencies.
48. Which output format is scalable and suitable for vector graphics?
- SVG
- TXT
- CSV
- JSONL
Answer: A) SVG
Explanation:
SVG is a scalable vector graphics format. Bokeh supports SVG output, including through export_svg() and related export functionality.
49. Which statement about standalone Bokeh documents is correct?
- They always require a Bokeh Server
- They can work without a Bokeh Server
- They can only be viewed inside Python
- They cannot contain JavaScript interactions
Answer: B) They can work without a Bokeh Server
Explanation:
Standalone Bokeh documents can be embedded or saved as HTML and do not require a Bokeh Server. They can still provide browser-side interactions using JavaScript callbacks and BokehJS.
50. Which statement best describes Bokeh?
- It is only a static plotting library
- It is only a database visualization tool
- It provides interactive visualizations, widgets, layouts, and web applications
- It is a replacement for JavaScript
Answer: C) It provides interactive visualizations, widgets, layouts, and web applications
Explanation:
Bokeh provides a broad set of tools for interactive visualization, including plots, glyphs, data sources, widgets, layouts, callbacks, standalone documents, and Bokeh Server applications.
Advertisement
Advertisement