Skip to content

GridX

plotynium.marks.GridX

GridX(data=None, x=None, y1=None, y2=None, stroke=None, stroke_opacity=0.1, stroke_width=1, stroke_dasharray=None)

Marker for adding vertical lines from x ticks.

Parameters:

Name Type Description Default

data

list[T]

List of x positions where vertical lines will be placed.

None

x

Callable[[T], Data] | str | None

X accessor function or key value

None

y1

Callable[[T], Data] | str | None

Y accessor function or key value for tail coordinates of the lines

None

y2

Callable[[T], Data] | str | None

Y accessor function or key value for head coordinates of the lines

None

stroke

Callable[[T], str] | str | None

Function which takes a data and returns a color applied for stroke attribute.

None

stroke_width

float

Stroke width value.

1

stroke_opacity

float

Stroke opacity value included in [0, 1].

0.1

stroke_dasharray

str | None

Stroke dasharray value.

None
Source code in plotynium/marks/grid.py
def __init__(
    self,
    data: list[T] | None = None,
    x: Callable[[T], Data] | str | None = None,
    y1: Callable[[T], Data] | None = None,
    y2: Callable[[T], Data] | None = None,
    stroke: str | None = None,
    stroke_opacity: float = 0.1,
    stroke_width: float = 1,
    stroke_dasharray: str | None = None,
):
    Mark.__init__(self)
    self._data = data or d3.ticks(0, 1, 10)
    self._x = x or Identity()
    self._y1 = y1
    self._y2 = y2
    self._stroke = stroke or "currentColor"
    self._stroke_opacity = stroke_opacity
    self._stroke_width = stroke_width
    self._stroke_dasharray = stroke_dasharray

    self.x_domain = domain(self._data, self._x)
    self.x_scaler_type = determine_scaler(self._data, self._x)

x_domain instance-attribute

x_domain = domain(_data, _x)

x_scaler_type instance-attribute

x_scaler_type = determine_scaler(_data, _x)

apply

apply(svg, ctx)

Add vertical lines from x ticks.

Parameters:

Name Type Description Default

svg

Selection

SVG Content

required

ctx

Context

Context

required
Source code in plotynium/marks/grid.py
def apply(self, svg: Selection, ctx: Context):
    """
    Add vertical lines from x ticks.

    Parameters
    ----------
    svg : Selection
        SVG Content
    ctx: Context
        Context
    """
    height = ctx.height
    margin_top = ctx.margin.top
    margin_bottom = ctx.margin.bottom
    y1 = self._y1 or Constant(margin_top)
    y2 = self._y2 or Constant(height - margin_bottom)
    g = svg.append("g").attr("aria-label", "x-grid").attr("stroke", self._stroke)
    if self._stroke_width:
        g.attr("stroke_width", self._stroke_width)
    if self._stroke_dasharray:
        g.attr("stroke-dasharray", self._stroke_dasharray)
    if self._stroke_opacity:
        g.attr("stroke-opacity", self._stroke_opacity)

    (
        g.select_all("line")
        .data(self._data)
        .join("line")
        .attr("x1", lambda d: ctx.x(d))
        .attr("x2", lambda d: ctx.x(d))
        .attr("y1", y1)
        .attr("y2", y2)
    )