Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalize sub-plot API and add documentation #13346

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions bokehjs/src/lib/models/scales/scale.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Transform} from "../transforms/transform"
import {Range} from "../ranges/range"
import {Range1d} from "../ranges/range1d"
import type {Arrayable, FloatArray} from "core/types"
import {ScreenArray} from "core/types"
import type * as p from "core/properties"
Expand All @@ -10,7 +9,7 @@ export namespace Scale {

export type Props = Transform.Props & {
source_range: p.Property<Range>
target_range: p.Property<Range1d>
target_range: p.Property<Range>
}
}

Expand All @@ -26,7 +25,7 @@ export abstract class Scale<T = number> extends Transform<T, number> {
static {
this.internal<Scale.Props>(({Ref}) => ({
source_range: [ Ref(Range) ],
target_range: [ Ref(Range1d) ],
target_range: [ Ref(Range) ],
}))
}

Expand Down
19 changes: 15 additions & 4 deletions src/bokeh/core/property/singletons.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,28 @@
# Imports
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
# Standard library imports
from typing import TYPE_CHECKING, TypeVar, Union

if TYPE_CHECKING:
from typing_extensions import TypeAlias

#-----------------------------------------------------------------------------
# General API
# Globals and constants
#-----------------------------------------------------------------------------

__all__ = (
"Intrinsic",
"Optional",
"Undefined",
)

T = TypeVar("T")

#-----------------------------------------------------------------------------
# General API
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Dev API
#-----------------------------------------------------------------------------
Expand All @@ -49,6 +58,8 @@ def __repr__(self) -> str:

Undefined = UndefinedType()

Optional: TypeAlias = Union[T, UndefinedType]

class IntrinsicType:
""" Indicates usage of the intrinsic default value of a property. """

Expand Down
36 changes: 31 additions & 5 deletions src/bokeh/plotting/_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
TimeDelta,
Tuple,
)
from ..core.property.singletons import Optional, Undefined
from ..models import (
ColumnDataSource,
CoordinateMapping,
Expand Down Expand Up @@ -224,12 +225,37 @@

def subplot(self,
*,
x_source: Range | None = None, y_source: Range | None = None,
x_scale: Scale | None = None, y_scale: Scale | None = None,
x_target: Range, y_target: Range,
x_source: Optional[Range] = Undefined,
y_source: Optional[Range] = Undefined,
x_scale: Optional[Scale] = Undefined,
y_scale: Optional[Scale] = Undefined,
x_target: Range,
y_target: Range,
) -> GlyphAPI:
""" Create a new sub-coordinate system and expose a plotting API. """
coordinates = CoordinateMapping(x_source=x_source, y_source=y_source, x_target=x_target, y_target=y_target)
"""
Create a new sub-coordinate system and expose the plotting API.

Example:

.. bokeh-plot::
:source-position: above

from bokeh.plotting import figure, show

p = figure(x_range=[0, 10], y_range=[0, 10])
p.subplot(x_target=[0, 1], y_target=p.y_range).circle([0, 1, 2], [0, 1, 2])
p.subplot(x_target=[2, 3], y_target=p.y_range).circle([0, 1, 2], [0, 1, 2])

show(p)
"""
coordinates = CoordinateMapping(

Check warning on line 251 in src/bokeh/plotting/_figure.py

View check run for this annotation

Codecov / codecov/patch

src/bokeh/plotting/_figure.py#L251

Added line #L251 was not covered by tests
x_source=x_source,
y_source=y_source,
x_scale=x_scale,
y_scale=y_scale,
x_target=x_target,
y_target=y_target,
)
return GlyphAPI(self, coordinates)

def hexbin(self, x, y, size, orientation="pointytop", palette="Viridis256", line_color=None, fill_color=None, aspect_scale=1, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion src/bokeh/plotting/glyph_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#-----------------------------------------------------------------------------

class GlyphAPI:
""" """
""" Generalized glyph/plotting API for figures and sub-plots. """

@property
def plot(self) -> Plot | None:
Expand Down