如何在Plotly中允许重复的刻度线标签? [英] How to allow Duplicate Tick Labels in Plotly?

查看:133
本文介绍了如何在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);

以下是描述问题的jsfiddle:

Following is the jsfiddle depicting the issue:

https://jsfiddle.net/mam8sgwx/

推荐答案

使用ticktext设置布局:

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

这是演示:

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>

这篇关于如何在Plotly中允许重复的刻度线标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆