Documentation
¶
Overview ¶
Package ticker chooses where the ticks of an axis go and how they are labelled. It is a port of the parts of matplotlib.ticker that a default matplotlib figure uses — AutoLocator (MaxNLocator), ScalarFormatter, LogLocator and LogFormatterSciNotation — and its results are tested to be equal to matplotlib's, tick for tick and label for label.
Index ¶
- func FixMinus(s string) string
- func FormatTicks(f Formatter, locs []float64, vmin, vmax float64) []string
- func Nonsingular(vmin, vmax, expander, tiny float64, increasing bool) (float64, float64)
- type Config
- type Formatter
- type Locator
- type LogFormatterSciNotation
- type LogLocator
- type MaxNLocator
- type ScalarFormatter
- type Tick
- type Ticks
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FixMinus ¶
FixMinus replaces every hyphen-minus with U+2212 MINUS SIGN, as matplotlib does when axes.unicode_minus is on (its default).
func FormatTicks ¶
FormatTicks is matplotlib's Formatter.format_ticks: SetLocs, then Format each location.
func Nonsingular ¶
Nonsingular is matplotlib's transforms.nonsingular: it widens an interval that is empty, tiny or not finite so that a scale can be built on it. With increasing set the result is ordered; otherwise a swapped input stays swapped.
Types ¶
type Config ¶
type Config struct {
Major Locator
Minor Locator
MajorFormat Formatter
MinorFormat Formatter
Log bool // the axis scale is logarithmic (base 10 transform)
}
Config is the locators and formatters of one axis. Minor and MinorFormat may be nil (no minor ticks), as on a linear axis by default.
func LinearConfig ¶
LinearConfig returns the configuration of a matplotlib linear axis on which tickSpace ticks fit: AutoLocator and ScalarFormatter, no minor ticks.
func LogConfig ¶
LogConfig returns the configuration of a matplotlib base-10 log axis on which tickSpace ticks fit; minPos is the smallest positive data value.
func (Config) Compute ¶
Compute returns the ticks of an axis whose view is [vmin, vmax], as matplotlib's Axis._update_ticks does: every major location is formatted (so that the format can depend on locations just outside the view), minor locations that coincide with major ones are dropped, and only the ticks within the view (to a relative 1e-10, in scale coordinates) are kept.
type Formatter ¶
type Formatter interface {
SetLocs(locs []float64, vmin, vmax float64)
Format(x float64) string
Offset() string
}
A Formatter turns tick locations into label strings. SetLocs is called once with every location the locator returned (including those outside the view) and the view interval; Format is then called per tick, and Offset returns the text shown at the end of the axis (an offset or a power of ten common to every label), or "".
Labels may contain TeX math between dollar signs, as matplotlib's do.
type Locator ¶
A Locator returns tick locations for a view interval. The locations may extend beyond the interval; the axis keeps only those inside it.
type LogFormatterSciNotation ¶
type LogFormatterSciNotation struct {
Base float64 // zero means 10
LabelOnlyBase bool
// MinorThresholds are matplotlib's minor_thresholds: label only the
// powers of the base when more than [0] decade boundaries are in view; a
// log-spaced subset when the view spans more than [1] decades; everything
// otherwise. The zero value means matplotlib's default (1, 0.4).
MinorThresholds [2]float64
// contains filtered or unexported fields
}
LogFormatterSciNotation is matplotlib's formatter for log axes: powers of the base as TeX ($10^{3}$), and other values as a coefficient times a power. Which non-decade ticks get a label at all depends on how many decades the view spans (MinorThresholds).
func NewLogFormatterSciNotation ¶
func NewLogFormatterSciNotation() *LogFormatterSciNotation
NewLogFormatterSciNotation returns the formatter matplotlib puts on a log axis: labelOnlyBase false, minor thresholds (1, 0.4). Its labels are TeX, where a minus is already a minus sign.
func (*LogFormatterSciNotation) Format ¶
func (f *LogFormatterSciNotation) Format(x float64) string
Format implements Formatter.
func (*LogFormatterSciNotation) Offset ¶
func (f *LogFormatterSciNotation) Offset() string
Offset implements Formatter: log axes have none.
func (*LogFormatterSciNotation) SetLocs ¶
func (f *LogFormatterSciNotation) SetLocs(_ []float64, vmin, vmax float64)
SetLocs implements Formatter. Only the view interval matters.
type LogLocator ¶
type LogLocator struct {
Base float64 // zero means 10
// Subs are the multiples of the powers of Base to tick at. Nil means {1}.
Subs []float64
// SubsAuto is matplotlib's subs="auto": ticks between the powers of Base
// (2..Base-1) when few decades are shown, none otherwise.
SubsAuto bool
// SubsAll is matplotlib's subs="all": like SubsAuto, but the powers of
// Base themselves are included, and when too many decades are shown it
// falls back to the powers alone.
SubsAll bool
// NumTicks is the maximum number of ticks; zero means "auto" (TickSpace
// clipped to [2, 9], or 9 when TickSpace is zero).
NumTicks int
TickSpace int
// MinPos is the smallest positive data value, used when vmin <= 0.
MinPos float64
}
LogLocator places ticks at Subs[j] * Base**i. It is matplotlib's LogLocator; with Subs nil it places the major ticks of a log axis, with SubsAuto the minor ones.
func (*LogLocator) TickValues ¶
func (l *LogLocator) TickValues(vmin, vmax float64) []float64
TickValues returns the tick locations for [vmin, vmax]. A vmin <= 0 is replaced by MinPos; with no positive value at all it returns nil.
type MaxNLocator ¶
type MaxNLocator struct {
// Nbins is the maximum number of intervals. Zero means "auto": TickSpace,
// clipped to [max(1, MinNTicks-1), 9], or 9 when TickSpace is zero.
Nbins int
// TickSpace is the number of ticks that fit on the axis, as the axis
// estimates it (matplotlib's Axis.get_tick_space). Used when Nbins is zero.
TickSpace int
// Steps are the acceptable multiples of a power of ten, in [1, 10],
// increasing. Nil means AutoLocator's {1, 2, 2.5, 5, 10}.
Steps []float64
// Integer restricts ticks to integer values.
Integer bool
// Symmetric makes the range symmetric about zero.
Symmetric bool
// Prune drops the "lower", "upper" or "both" extreme ticks.
Prune string
// MinNTicks is the minimum number of ticks in the interval; at least 1.
MinNTicks int
}
MaxNLocator finds up to Nbins+1 nicely rounded tick locations, nice meaning a multiple of one of Steps times a power of ten. It is matplotlib's MaxNLocator; NewAutoLocator returns it configured as matplotlib's AutoLocator, the default for linear axes.
func NewAutoLocator ¶
func NewAutoLocator(tickSpace int) *MaxNLocator
NewAutoLocator returns matplotlib's AutoLocator: nbins "auto", steps {1, 2, 2.5, 5, 10}, at least two ticks.
func (*MaxNLocator) TickValues ¶
func (l *MaxNLocator) TickValues(vmin, vmax float64) []float64
TickValues returns the tick locations for [vmin, vmax].
type ScalarFormatter ¶
type ScalarFormatter struct {
UseOffset bool
OffsetThreshold int // digits an offset must save before it is used
PowerLimits [2]int // scientific notation for exponents <= [0] or >= [1]
Scientific bool
UseMathText bool // write the offset as a TeX ×10^n
UnicodeMinus bool // write U+2212 rather than a hyphen
// contains filtered or unexported fields
}
ScalarFormatter is matplotlib's default formatter for linear axes: plain decimals with just enough digits to tell the ticks apart, an offset when every tick shares a long common prefix, and scientific notation (a common power of ten shown at the end of the axis) outside PowerLimits.
func NewScalarFormatter ¶
func NewScalarFormatter() *ScalarFormatter
NewScalarFormatter returns a ScalarFormatter with matplotlib's defaults.
func (*ScalarFormatter) Format ¶
func (f *ScalarFormatter) Format(x float64) string
Format implements Formatter.
func (*ScalarFormatter) Offset ¶
func (f *ScalarFormatter) Offset() string
Offset implements Formatter.
func (*ScalarFormatter) SetLocs ¶
func (f *ScalarFormatter) SetLocs(locs []float64, vmin, vmax float64)
SetLocs implements Formatter.
type Ticks ¶
type Ticks struct {
Major, Minor []Tick
Offset string // text at the end of the axis, or ""
// Located is every major location the locator returned, inside the view
// or not, with its label: what matplotlib's get_ticklabels() lists.
Located []Tick
}
Ticks is what an axis draws for one view interval.