Skip to content

feat: Add minorloglabels to cartesian axes #7468

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

Merged
merged 6 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/7468_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add `minorloglabels` to cartesian axes [#7468](https://github.com/plotly/plotly.js/pull/7468)
31 changes: 23 additions & 8 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1899,26 +1899,41 @@ function formatLog(ax, out, hover, extraPrecision, hideexp) {

if(tickformat || (dtChar0 === 'L')) {
out.text = numFormat(Math.pow(10, x), ax, hideexp, extraPrecision);
} else if(isNumeric(dtick) || ((dtChar0 === 'D') && (Lib.mod(x + 0.01, 1) < 0.1))) {
var p = Math.round(x);
} else if(isNumeric(dtick) || ((dtChar0 === 'D') &&
(ax.minorloglabels === 'complete' || Lib.mod(x + 0.01, 1) < 0.1))) {

var isMinor;
if(ax.minorloglabels === 'complete' && !(Lib.mod(x + 0.01, 1) < 0.1)) {
isMinor = true;
out.fontSize *= 0.75;
}

var exponentialString = Math.pow(10, x).toExponential(0);
var parts = exponentialString.split('e');

var p = +parts[1];
var absP = Math.abs(p);
var exponentFormat = ax.exponentformat;
if(exponentFormat === 'power' || (isSIFormat(exponentFormat) && beyondSI(p))) {
if(p === 0) out.text = 1;
else if(p === 1) out.text = '10';
else out.text = '10<sup>' + (p > 1 ? '' : MINUS_SIGN) + absP + '</sup>';
out.text = parts[0];
if(absP > 0) out.text += 'x10';
if(out.text === '1x10') out.text = '10';
if(p !== 0 && p !== 1) out.text += '<sup>' + (p > 0 ? '' : MINUS_SIGN) + absP + '</sup>';

out.fontSize *= 1.25;
} else if((exponentFormat === 'e' || exponentFormat === 'E') && absP > 2) {
out.text = '1' + exponentFormat + (p > 0 ? '+' : MINUS_SIGN) + absP;
out.text = parts[0] + exponentFormat + (p > 0 ? '+' : MINUS_SIGN) + absP;
} else {
out.text = numFormat(Math.pow(10, x), ax, '', 'fakehover');
if(dtick === 'D1' && ax._id.charAt(0) === 'y') {
out.dy -= out.fontSize / 6;
}
}
} else if(dtChar0 === 'D') {
out.text = String(Math.round(Math.pow(10, Lib.mod(x, 1))));
out.text =
ax.minorloglabels === 'none' ? '' :
/* ax.minorloglabels === 'small digits' */ String(Math.round(Math.pow(10, Lib.mod(x, 1))));

out.fontSize *= 0.75;
} else throw 'unrecognized dtick ' + String(dtick);

Expand Down Expand Up @@ -3770,7 +3785,7 @@ axes.drawLabels = function(gd, ax, opts) {

var sel;
if(e.K === ZERO_PATH.K) {
var zerolineLayer = zerolineIsAbove ? mainPlotinfo.zerolinelayerAbove : mainPlotinfo.zerolinelayer;
var zerolineLayer = zerolineIsAbove ? mainPlotinfo.zerolinelayerAbove : mainPlotinfo.zerolinelayer;
sel = zerolineLayer.selectAll('.' + ax._id + 'zl');
} else if(e.K === MINORGRID_PATH.K) sel = mainPlotinfo.minorGridlayer.selectAll('.' + ax._id);
else if(e.K === GRID_PATH.K) sel = mainPlotinfo.gridlayer.selectAll('.' + ax._id);
Expand Down
13 changes: 13 additions & 0 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,19 @@ module.exports = {
editType: 'ticks'
},

minorloglabels: {
valType: 'enumerated',
values: ['small digits', 'complete', 'none'],
dflt: 'small digits',
editType: 'calc',
description: [
'Determines how minor log labels are displayed.',
'If *small digits*, small digits i.e. 2 or 5 are displayed.',
'If *complete*, complete digits are displayed.',
'If *none*, no labels are displayed.',
].join(' ')
},

layer: {
valType: 'enumerated',
values: ['above traces', 'below traces'],
Expand Down
4 changes: 4 additions & 0 deletions src/plots/cartesian/tick_label_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ module.exports = function handleTickLabelDefaults(containerIn, containerOut, coe
coerce('separatethousands');
}
}

if(!options.noMinorloglabels && axType === 'log') {
coerce('minorloglabels');
}
}
};

Expand Down
1 change: 1 addition & 0 deletions src/plots/gl3d/layout/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, options) {
data: options.data,
showGrid: true,
noAutotickangles: true,
noMinorloglabels: true,
noTicklabelindex: true,
noTickson: true,
noTicklabelmode: true,
Expand Down
1 change: 1 addition & 0 deletions src/plots/polar/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var axisTickAttrs = overrideAll({
ticklabelstep: axesAttrs.ticklabelstep,
showticklabels: axesAttrs.showticklabels,
labelalias: axesAttrs.labelalias,
minorloglabels: axesAttrs.minorloglabels,
showtickprefix: axesAttrs.showtickprefix,
tickprefix: axesAttrs.tickprefix,
showticksuffix: axesAttrs.showticksuffix,
Expand Down
Binary file added test/image/baselines/zz-minorloglabels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions test/image/mocks/zz-minorloglabels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"data": [{
"x": [0.001, 0.01, 0.1, 1, 10, 100, 1000],
"y": [0, 1, 2, 3, 4, 5, 6]
}, {
"xaxis": "x2",
"yaxis": "y2",
"x": [0.001, 0.01, 0.1, 1, 10, 100, 1000],
"y": [0, 1, 2, 3, 4, 5, 6]
}, {
"xaxis": "x3",
"yaxis": "y3",
"x": [0.001, 0.01, 0.1, 1, 10, 100, 1000],
"y": [0, 1, 2, 3, 4, 5, 6]
}, {
"xaxis": "x4",
"yaxis": "y4",
"x": [0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000, 10000, 100000],
"y": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
}, {
"xaxis": "x5",
"yaxis": "y5",
"x": [0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000, 10000, 100000],
"y": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
}, {
"xaxis": "x6",
"yaxis": "y6",
"x": [0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000, 10000, 100000],
"y": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
}],
"layout": {
"grid": {
"rows": 7,
"columns": 1,
"ygap": 0.8,
"pattern": "independent"
},
"xaxis": {
"title": { "text": "none" },
"type": "log",
"minorloglabels": "none",
"minor": { "showgrid": true }
},
"xaxis2": {
"title": { "text": "small digits" },
"dtick": "D1",
"type": "log",
"minorloglabels": "small digits"
},
"xaxis3": {
"title": { "text": "small digits" },
"dtick": "D2",
"type": "log",
"minorloglabels": "small digits"
},
"xaxis4": {
"title": { "text": "complete" },
"dtick": "D2",
"type": "log",
"minorloglabels": "complete",
"minor": { "showgrid": true }
},
"xaxis5": {
"title": { "text": "complete <br> exponentformat: 'e'" },
"exponentformat": "e",
"dtick": "D2",
"type": "log",
"minorloglabels": "complete",
"minor": { "showgrid": true }
},
"xaxis6": {
"title": { "text": "complete <br> exponentformat: 'power'" },
"exponentformat": "power",
"dtick": "D2",
"type": "log",
"minorloglabels": "complete",
"minor": { "showgrid": true }
},
"title": {
"text": "options of minorloglabels"
},
"width": 1400,
"height": 1200,
"showlegend": false
}
}
44 changes: 44 additions & 0 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5197,6 +5197,17 @@
"min": 0,
"valType": "number"
},
"minorloglabels": {
"description": "Determines how minor log labels are displayed. If *small digits*, small digits i.e. 2 or 5 are displayed. If *complete*, complete digits are displayed. If *none*, no labels are displayed.",
"dflt": "small digits",
"editType": "plot",
"valType": "enumerated",
"values": [
"small digits",
"complete",
"none"
]
},
"nticks": {
"description": "Specifies the maximum number of ticks for the particular axis. The actual number of ticks will be chosen automatically to be less than or equal to `nticks`. Has an effect only if `tickmode` is set to *auto*.",
"dflt": 0,
Expand Down Expand Up @@ -5894,6 +5905,17 @@
"min": 0,
"valType": "number"
},
"minorloglabels": {
"description": "Determines how minor log labels are displayed. If *small digits*, small digits i.e. 2 or 5 are displayed. If *complete*, complete digits are displayed. If *none*, no labels are displayed.",
"dflt": "small digits",
"editType": "plot",
"valType": "enumerated",
"values": [
"small digits",
"complete",
"none"
]
},
"nticks": {
"description": "Specifies the maximum number of ticks for the particular axis. The actual number of ticks will be chosen automatically to be less than or equal to `nticks`. Has an effect only if `tickmode` is set to *auto*.",
"dflt": 0,
Expand Down Expand Up @@ -13907,6 +13929,17 @@
"valType": "number"
}
},
"minorloglabels": {
"description": "Determines how minor log labels are displayed. If *small digits*, small digits i.e. 2 or 5 are displayed. If *complete*, complete digits are displayed. If *none*, no labels are displayed.",
"dflt": "small digits",
"editType": "calc",
"valType": "enumerated",
"values": [
"small digits",
"complete",
"none"
]
},
"mirror": {
"description": "Determines if the axis lines or/and ticks are mirrored to the opposite side of the plotting area. If *true*, the axis lines are mirrored. If *ticks*, the axis lines and ticks are mirrored. If *false*, mirroring is disable. If *all*, axis lines are mirrored on all shared-axes subplots. If *allticks*, axis lines and ticks are mirrored on all shared-axes subplots.",
"dflt": false,
Expand Down Expand Up @@ -15468,6 +15501,17 @@
"valType": "number"
}
},
"minorloglabels": {
"description": "Determines how minor log labels are displayed. If *small digits*, small digits i.e. 2 or 5 are displayed. If *complete*, complete digits are displayed. If *none*, no labels are displayed.",
"dflt": "small digits",
"editType": "calc",
"valType": "enumerated",
"values": [
"small digits",
"complete",
"none"
]
},
"mirror": {
"description": "Determines if the axis lines or/and ticks are mirrored to the opposite side of the plotting area. If *true*, the axis lines are mirrored. If *ticks*, the axis lines and ticks are mirrored. If *false*, mirroring is disable. If *all*, axis lines are mirrored on all shared-axes subplots. If *allticks*, axis lines and ticks are mirrored on all shared-axes subplots.",
"dflt": false,
Expand Down