Parallel Coordinates Plot in JavaScript

How to make D3.js-based parallel coordinates plots in Plotly.js.


Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Try Plotly Studio now.

Parallel coordinates are richly interactive by default. Drag the lines along the axes to filter regions and drag the axis names across the plot to rearrange variables: IPython terminal

var trace = {
  type: 'parcoords',
  line: {
    color: 'blue'
  },
  
  dimensions: [{
    range: [1, 5],
    constraintrange: [1, 2],
    label: 'A',
    values: [1,4]
  }, {    
    range: [1,5],
    label: 'B',
    values: [3,1.5],
    tickvals: [1.5,3,4.5]
  }, {
    range: [1, 5],
    label: 'C',
    values: [2,4],
    tickvals: [1,2,4,5],
    ticktext: ['text 1','text 2','text 4','text 5']
  }, {
    range: [1, 5],
    label: 'D',
    values: [4,2]
  }]
};

var data = [trace]

Plotly.newPlot('myDiv', data);
</script>\n</head>\n\n<body>\n\t<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>\n</body>","js":"var trace = {\n type: 'parcoords',\n line: {\n color: 'blue'\n },\n \n dimensions: [{\n range: [1, 5],\n constraintrange: [1, 2],\n label: 'A',\n values: [1,4]\n }, { \n range: [1,5],\n label: 'B',\n values: [3,1.5],\n tickvals: [1.5,3,4.5]\n }, {\n range: [1, 5],\n label: 'C',\n values: [2,4],\n tickvals: [1,2,4,5],\n ticktext: ['text 1','text 2','text 4','text 5']\n }, {\n range: [1, 5],\n label: 'D',\n values: [4,2]\n }]\n};\n\nvar data = [trace]\n\nPlotly.newPlot('myDiv', data);\n"}">
d3.csv('https://raw.githubusercontent.com/bcdunbar/datasets/master/iris.csv', function(err, rows){

function unpack(rows, key) {
  return rows.map(function(row) {
    return row[key];
  });
}

var data = [{
  type: 'parcoords',
  pad: [80,80,80,80],
  line: {
    color: unpack(rows, 'species_id'),
    colorscale: [[0, 'red'], [0.5, 'green'], [1, 'blue']]
  },

  dimensions: [{
    range: [2, 4.5],
    label: 'sepal_width',
    values: unpack(rows, 'sepal_width')
  }, {
    constraintrange: [5, 6],
    range: [4,8],
    label: 'sepal_length',
    values: unpack(rows, 'sepal_length')
  }, {
    label: 'petal_width',
    range: [0, 2.5],
    values: unpack(rows, 'petal_width')
  }, {
    label: 'petal_length',
    range: [1, 7],
    values: unpack(rows, 'petal_length')
  }]
}];

var layout = {
  width: 800
};

Plotly.newPlot('myDiv', data, layout);

});
</script>\n\t<script src="/?originalUrl=https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fd3%2F3.5.17%2Fd3.min.js"></script>\n</head>\n\n<body>\n\t<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>\n</body>","js":"d3.csv('https://raw.githubusercontent.com/bcdunbar/datasets/master/iris.csv', function(err, rows){\n\nfunction unpack(rows, key) {\n return rows.map(function(row) {\n return row[key];\n });\n}\n\nvar data = [{\n type: 'parcoords',\n pad: [80,80,80,80],\n line: {\n color: unpack(rows, 'species_id'),\n colorscale: [[0, 'red'], [0.5, 'green'], [1, 'blue']]\n },\n\n dimensions: [{\n range: [2, 4.5],\n label: 'sepal_width',\n values: unpack(rows, 'sepal_width')\n }, {\n constraintrange: [5, 6],\n range: [4,8],\n label: 'sepal_length',\n values: unpack(rows, 'sepal_length')\n }, {\n label: 'petal_width',\n range: [0, 2.5],\n values: unpack(rows, 'petal_width')\n }, {\n label: 'petal_length',\n range: [1, 7],\n values: unpack(rows, 'petal_length')\n }]\n}];\n\nvar layout = {\n width: 800\n};\n\nPlotly.newPlot('myDiv', data, layout);\n\n});\n"}">
d3.csv('https://raw.githubusercontent.com/plotly/datasets/master/iris-id.csv', function(err, rows){

function unpack(rows, key) {
  return rows.map(function(row) {
    return row[key];
  });
}

var data = [{
  type: 'parcoords',
  pad: [80,80,80,80],
  line: {
    color: unpack(rows, 'species_id'),
    colorscale: [[0, 'red'], [0.5, 'green'], [1, 'blue']]
  },

  dimensions: [{
    range: [2, 4.5],
    label: 'sepal_width',
    values: unpack(rows, 'sepal_width')
  }, {
    constraintrange: [5, 6],
    range: [4,8],
    label: 'sepal_length',
    values: unpack(rows, 'sepal_length')
  }, {
    label: 'petal_width',
    range: [0, 2.5],
    values: unpack(rows, 'petal_width')
  }, {
    label: 'petal_length',
    range: [1, 7],
    values: unpack(rows, 'petal_length')
  }]
}];

var layout = {
  width: 800,
  annotations: [
	  {showarrow: false,
      text: 'Higher sepal width',
      x: 0, y: 1, xref: 'paper', yref: 'paper'},
	  {showarrow: false,
      text: 'Lower petal width and length',
      x: 0.9, y: .25, xref: 'paper', yref: 'paper'
    }]
};

Plotly.newPlot('myDiv', data, layout);

});
</script>\n\t<script src="/?originalUrl=https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fd3%2F3.5.17%2Fd3.min.js"></script>\n</head>\n\n<body>\n\t<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>\n</body>","js":"d3.csv('https://raw.githubusercontent.com/plotly/datasets/master/iris-id.csv', function(err, rows){\n\nfunction unpack(rows, key) {\n return rows.map(function(row) {\n return row[key];\n });\n}\n\nvar data = [{\n type: 'parcoords',\n pad: [80,80,80,80],\n line: {\n color: unpack(rows, 'species_id'),\n colorscale: [[0, 'red'], [0.5, 'green'], [1, 'blue']]\n },\n\n dimensions: [{\n range: [2, 4.5],\n label: 'sepal_width',\n values: unpack(rows, 'sepal_width')\n }, {\n constraintrange: [5, 6],\n range: [4,8],\n label: 'sepal_length',\n values: unpack(rows, 'sepal_length')\n }, {\n label: 'petal_width',\n range: [0, 2.5],\n values: unpack(rows, 'petal_width')\n }, {\n label: 'petal_length',\n range: [1, 7],\n values: unpack(rows, 'petal_length')\n }]\n}];\n\nvar layout = {\n width: 800,\n annotations: [\n\t {showarrow: false,\n text: 'Higher sepal width',\n x: 0, y: 1, xref: 'paper', yref: 'paper'},\n\t {showarrow: false,\n text: 'Lower petal width and length',\n x: 0.9, y: .25, xref: 'paper', yref: 'paper'\n }]\n};\n\nPlotly.newPlot('myDiv', data, layout);\n\n});\n"}">
d3.csv('https://raw.githubusercontent.com/bcdunbar/datasets/master/parcoords_data.csv', function(err, rows){

function unpack(rows, key) {
  return rows.map(function(row) {
    return row[key];
  });
}

var data = [{
  type: 'parcoords',
  line: {
    showscale: true,
    reversescale: true,
    colorscale: 'Jet',
    cmin: -4000,
    cmax: -100,
    color: unpack(rows, 'colorVal')
  },

  dimensions: [{
    constraintrange: [100000, 150000],
    range: [32000, 227900],
    label: 'Block height',
    values: unpack(rows, 'blockHeight')
  }, {
    range: [0, 700000],
    label: 'Block width',
    values: unpack(rows, 'blockWidth')
  }, {
    label: 'Cylinder material',
    tickvals: [0, 0.5, 1, 2, 3],
    ticktext: ['A', 'AB', 'B', 'Y', 'Z'],
    values: unpack(rows, 'cycMaterial')
  }, {
    label: 'Block material',
    tickvals: [0, 1, 2, 3],
    range: [-1, 4],
    values: unpack(rows, 'blockMaterial')
  }, {
    range: [134, 3154],
    label: 'Total weight',
    visible: true,
    values: unpack(rows, 'totalWeight')
  }, {
    range: [9, 19984],
    label: 'Assembly penalty weight',
    values: unpack(rows, 'assemblyPW')
  }, {
    range: [49000, 568000],
    label: 'Height st width',
    values: unpack(rows, 'HstW')
  }, {
    range: [-28000, 196430],
    label: 'Min height width',
    values: unpack(rows, 'minHW')
  }, {
     range: [98453, 501789],
     label: 'Min width diameter',
     values: unpack(rows, 'minWD')
  }, {
    range: [1417, 107154],
    label: 'RF block',
    values: unpack(rows, 'rfBlock')
  }]
}];

Plotly.newPlot('myDiv', data);

});
</script>\n\t<script src="/?originalUrl=https%3A%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fd3%2F3.5.17%2Fd3.min.js"></script>\n</head>\n\n<body>\n\t<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>\n</body>","js":"d3.csv('https://raw.githubusercontent.com/bcdunbar/datasets/master/parcoords_data.csv', function(err, rows){\n\nfunction unpack(rows, key) {\n return rows.map(function(row) {\n return row[key];\n });\n}\n\nvar data = [{\n type: 'parcoords',\n line: {\n showscale: true,\n reversescale: true,\n colorscale: 'Jet',\n cmin: -4000,\n cmax: -100,\n color: unpack(rows, 'colorVal')\n },\n\n dimensions: [{\n constraintrange: [100000, 150000],\n range: [32000, 227900],\n label: 'Block height',\n values: unpack(rows, 'blockHeight')\n }, {\n range: [0, 700000],\n label: 'Block width',\n values: unpack(rows, 'blockWidth')\n }, {\n label: 'Cylinder material',\n tickvals: [0, 0.5, 1, 2, 3],\n ticktext: ['A', 'AB', 'B', 'Y', 'Z'],\n values: unpack(rows, 'cycMaterial')\n }, {\n label: 'Block material',\n tickvals: [0, 1, 2, 3],\n range: [-1, 4],\n values: unpack(rows, 'blockMaterial')\n }, {\n range: [134, 3154],\n label: 'Total weight',\n visible: true,\n values: unpack(rows, 'totalWeight')\n }, {\n range: [9, 19984],\n label: 'Assembly penalty weight',\n values: unpack(rows, 'assemblyPW')\n }, {\n range: [49000, 568000],\n label: 'Height st width',\n values: unpack(rows, 'HstW')\n }, {\n range: [-28000, 196430],\n label: 'Min height width',\n values: unpack(rows, 'minHW')\n }, {\n range: [98453, 501789],\n label: 'Min width diameter',\n values: unpack(rows, 'minWD')\n }, {\n range: [1417, 107154],\n label: 'RF block',\n values: unpack(rows, 'rfBlock')\n }]\n}];\n\nPlotly.newPlot('myDiv', data);\n\n});\n"}">