Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow Duplicate Tick Labels in Plotly?

Tags:

d3.js

plotly

I observed that while providing duplicate ticklabels (with an aim to mention the class of categorical variable), plotly creates a unique set and displays only the non-repeated tick labels. Is there a way to by-pass this feature and allow duplicate tick-labels?

var data = [
 {
z: [[1, 20, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, -10, 20]],
x: ['Healthy', 'Healthy', 'Moderate', 'Diseased', 'Diseased'],
y: ['Morning', 'Afternoon', 'Evening'],
type: 'heatmap'
}
];

Plotly.newPlot('myDiv', data);

Following is the jsfiddle depicting the issue:

https://jsfiddle.net/mam8sgwx/

like image 422
JALO - JusAnotherLivngOrganism Avatar asked Oct 17 '25 07:10

JALO - JusAnotherLivngOrganism


1 Answers

Set the layout with ticktext:

var layout = {
    xaxis: {
        tickmode: "array",
        ticktext: ['Healthy', 'Healthy', 'Moderate', 'Diseased', 'Diseased'],
        tickvals: [0, 1, 2, 3, 4]
    }
}

Here is the demo:

var data = [{
    z: [
        [1, 20, 30, 50, 1],
        [20, 1, 60, 80, 30],
        [30, 60, 1, -10, 20]
    ],
    y: ['Morning', 'Afternoon', 'Evening'],
    type: 'heatmap'
}];

var layout = {
    xaxis: {
        tickmode: "array",
        ticktext: ['Healthy', 'Healthy', 'Moderate', 'Diseased', 'Diseased'],
        tickvals: [0, 1, 2, 3, 4]
    }
}

Plotly.newPlot('myDiv', data, layout);
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<body>
<div id="myDiv"></div>
like image 199
Gerardo Furtado Avatar answered Oct 19 '25 07:10

Gerardo Furtado



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!