question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allow users to specify explicit tick labels

See original GitHub issue

FixedTicker allows users to specify fixed tick locations, but also need to allow users to specify explicit tick labels

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:2
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
bryevdvcommented, May 2, 2017

Ok I’d like to do something for this for 0.12.6. There’s alot that’s somewhat tangential above, mostly I’d like to return to @pzwang observation that users should not be unduly burdened with considering tickers and formatters unless it’s necessary. So I propose the following:

plot.xaxis.major_label_overrides = { 5: "0-10", 15: "10-20", ... } 

Then internally axis models would pass this on to their tick formatters on init (or when a formatter is replaced). All the built in formatters would refer to this list of overrides (and extension formatters could as well). Users would only need to worry about supplying this mapping on an axis, which is a bit more common/approachable than tickers and formatter.

This would let specific values be overridden, however they occur. If only these ticks are desired, use of FixedTickFormatter would still be needed. However we could probably also make it so that

plot.xaxis.ticker = [5, 15, ... ]

works as a shorthand for setting up a fixed ticker.

Does this sound acceptable to everyone? If so I would plan on working on this after the refactor of categorical values.

2reactions
canavandlcommented, Mar 23, 2017

@tommycarstensen , I haven’t tested it, but the below should work:

from bokeh.plotting import show
from bokeh.properties import Dict, Int, String
from bokeh.models import (
    Plot,
    Range1d,
    LinearAxis,
    FixedTicker,
    TickFormatter,
)
from bokeh.util.compiler import CoffeeScript

class FixedTickFormatter(TickFormatter):
    """
    Class used to allow custom axis tick labels on a bokeh chart
    Extends bokeh.model.formatters.TickFormatter
    """

    COFFEESCRIPT =  """
        import {Model} from "model"
        import * as p from "core/properties"
        export class FixedTickFormatter extends Model
          type: 'FixedTickFormatter'
          doFormat: (ticks) ->
            labels = @get("labels")
            return (labels[tick] ? "" for tick in ticks)
          @define {
            labels: [ p.Any ]
          }
    """

    labels = Dict(Int, String, help="""
    A mapping of integer ticks values to their labels.
    """)

    __implementation__ = CoffeeScript(COFFEESCRIPT)

ticker = FixedTicker(ticks=[5,15,25,35,45,55])
formatter = FixedTickFormatter(labels={5: '0-10', 15: '10-20', 25: '20-30', 35: '30-40', 45: '40-50', 55: '50+'})
x_axis = LinearAxis(ticker=ticker, formatter=formatter)

p = Plot(x_range=Range1d(0,60))
p.add_layout(x_axis, 'below')

show(p)
Read more comments on GitHub >

github_iconTop Results From Across the Web

NCL Graphics: Tick marks
This setting allows the user to explicitly specify labels. Note, when tmXBMode is set to Explicit, the bottom X-axis minor tick marks are...
Read more >
How do I use custom labels for ticks in Bokeh? - Stack Overflow
Fixed ticks can just be passed directly as the "ticker" value, and major label overrides can be provided to explicitly supply custom labels...
Read more >
Pgfplots with custom axis markers - LaTeX Stack Exchange
Use \xtick to specify where you want the ticks, and \xticklabels to specify the corresponding labels.
Read more >
FAQ-116 How do I add or hide tick marks at specific values on ...
Go to the Special Ticks tab. Double click on a cell to edit the axis value or label for a special tick:
Read more >
Matplotlib - Setting Ticks and Tick Labels
Similarly, labels corresponding to tick marks can be set by set_xlabels() and set_ylabels() functions respectively. ax.set_xlabels(['two', 'four ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found