markers¶
Display a variety of simple scatter marker shapes whose attributes
can be associated with data columns from
ColumnDataSource
objects.
Warning
The individual marker classes in this module are deprecated since Bokeh
2.3.0. Please replace all occurrences of Marker
models with
Scatter
glyphs. For example: instead of
Asterisk()
, use Scatter(marker="asterisk")
.
For backwards compatibility, all markers in this module currently link to
their respective replacements using the
Scatter
glyph.
By definition, all markers accept the following set of properties:
x
,y
positionsize
in pixelsline
,fill
, andhatch
propertiesangle
The asterisk
, cross
, dash
, dot
, x
, and y
only render
line components. Those markers ignore any values that are passed to the fill
and hatch
properties.
Note
When you draw circle
markers with Scatter
, you can only assign a
size in screen units (by passing a number of pixels to the size
property). In case you want to define the radius of circles in
data units, use the Circle
glyph instead
of the Scatter
glyph.
Circle¶
- Circle(*args, **kwargs) Model [source]¶
Render circle markers.
Example
import numpy as np from bokeh.io import curdoc, show from bokeh.models import Circle, ColumnDataSource, Grid, LinearAxis, Plot N = 9 x = np.linspace(-2, 2, N) y = x**2 sizes = np.linspace(10, 20, N) source = ColumnDataSource(dict(x=x, y=y, sizes=sizes)) plot = Plot( title=None, width=300, height=300, min_border=0, toolbar_location=None) glyph = Circle(x="x", y="y", size="sizes", line_color="#3288bd", fill_color="white", line_width=3) plot.add_glyph(source, glyph) xaxis = LinearAxis() plot.add_layout(xaxis, 'below') yaxis = LinearAxis() plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) curdoc().add_root(plot) show(plot)
CircleCross¶
CircleX¶
CircleY¶
DiamondCross¶
DiamondDot¶
InvertedTriangle¶
Marker¶
- Marker(*args, **kwargs) Model [source]¶
Base class for glyphs that are simple markers with line and fill properties, located at an (x, y) location with a specified size.
Note
For simplicity, all markers have both line and fill properties declared, however some marker types (asterisk, cross, x) only draw lines. For these markers, the fill values are simply ignored.
Note
This is an abstract base class used to help organize the hierarchy of Bokeh model types. It is not useful to instantiate on its own.
Scatter¶
- Scatter(*args, **kwargs) Model [source]¶
Render scatter markers selected from a predefined list of designs.
Use
Scatter
to draw any of Bokeh’s built-in marker types:asterisk
,circle
,circle_cross
,circle_dot
,circle_x
,circle_y
,cross
,dash
,diamond
,diamond_cross
,diamond_dot
,dot
,hex
,hex_dot
,inverted_triangle
,plus
,square
,square_cross
,square_dot
,square_pin
,square_x
,star
,star_dot
,triangle
,triangle_dot
,triangle_pin
,x
, ory
. This collection is available inMarkerType
.Bokeh’s built-in markers consist of a set of base markers, most of which can be combined with different kinds of additional visual features:
You can select marker types in two ways:
To draw the same marker for all values, use the
marker
attribute to specify the name of a specific marker. For example:glyph = Scatter(x="x", y="y", size="sizes", marker="square") plot.add_glyph(source, glyph)
This will render square markers for all points.
Alternatively, to use marker types specified in a data source column, assign the column name to the
marker
attribute. For example:# source.data['markers'] = ["circle", "square", "circle", ... ] glyph = Scatter(x="x", y="y", size="sizes", marker="markers") plot.add_glyph(source, glyph)
Note
When you draw
circle
markers withScatter
, you can only assign a size in screen units (by passing a number of pixels to thesize
property). In case you want to define the radius of circles in data units, use theCircle
glyph instead of theScatter
glyph.Example
import numpy as np from bokeh.core.enums import MarkerType from bokeh.io import curdoc, show from bokeh.models import ColumnDataSource, Grid, LinearAxis, Plot, Scatter N = len(MarkerType) x = np.linspace(-2, 2, N) y = x**2 markers = list(MarkerType) source = ColumnDataSource(dict(x=x, y=y, markers=markers)) plot = Plot( title=None, width=300, height=300, min_border=0, toolbar_location=None) glyph = Scatter(x="x", y="y", size=20, fill_color="#74add1", marker="markers") plot.add_glyph(source, glyph) xaxis = LinearAxis() plot.add_layout(xaxis, 'below') yaxis = LinearAxis() plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) curdoc().add_root(plot) show(plot)