How to allow Duplicate Tick Labels in Plotly?

倖福魔咒の 提交于 2019-12-24 07:13:48

问题


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/


回答1:


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>


来源:https://stackoverflow.com/questions/41298571/how-to-allow-duplicate-tick-labels-in-plotly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!