Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
  <!-- Plotly.js -->
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>

<body>
  <header>
    <h1>Heat Map with Plotly.js</h1>
  </header>
  
  <div id="myDiv"><!-- Plotly chart will be drawn inside this DIV --></div>
  
  <footer>
    Digital version based on a chart from the research report:<br>
    <a target="_blank" rel="noreferrer noopener" href="https://6aika.fi/wp-content/uploads/2019/06/Datan-tietosuoja-ja-tietoturvallinen-avaaminen.pdf">Datan tietosuoja ja tietoturvallinen avaaminen (PDF file)</a>
  </footer>
  
  <script>
    <!-- JAVASCRIPT CODE GOES HERE -->
  </script>
</body>
              
            
!

CSS

              
                body {
  margin: 0;
  padding: 2ex;
  background-color: #ddd;
}

header {
  padding: 0;
  text-align: center;

  h1 {
    font-size: 4ex;
    color: #111;
  }
}

footer {
  padding: 2ex;
  text-align: center;
  
  a {
    display: inline-block;
    margin: 0.5ex;
    padding: 1ex;
    color: #000;   
    
    &:hover,
    &:focus {
      color: blue;
      background: #fff;
    }
  }
}

              
            
!

JS

              
                const xValues = [
  "Erittäin pieni merkitys",
  "Pieni merkitys",
  "Kohtuullinen merkitys",
  "Suuri merkitys",
  "Erittäin suuri merkitys"
];

const yValues = [
  "Erittäin alhainen todennäköisyys",
  "Alhainen todennäköisyys",
  "Kohtuullinen todennäköisyys",
  "Suuri todennäköisyys",
  "Erittäin suuri todennäköisyys"
];

const zValues = [
  [100, 100, 60, 60, 60],
  [100, 60, 60, 40, 40],
  [60, 60, 40, 40, 20],
  [60, 40, 40, 20, 0],
  [60, 40, 20, 0, 0]
];

// Custom color scale
// - https://plot.ly/javascript/colorscales/
const colorscaleValue = [
  [0, "#5c9ad7"],
  [20, "#71ac47"],
  [40, "#ffff01"],
  [60, "#ee7e32"],
  [100, "#0000ff"]
];

// Range: 0-100
const data = [
  {
    z: zValues,
    x: xValues,
    y: yValues,
    type: "heatmap",
    // colorscale: colorscaleValue,
    // colorscale: 'Viridis',
    // colorscale: 'Jet',
    colorscale: "Portland",
    showscale: false
  }
];

const dataAnnotations = [
  {
    x: 0,
    y: 0,
    xref: "x",
    yref: "y",
    text: "Erittäin pieni hyöty",
    showarrow: true,
    arrowhead: 3,
    arrowsize: 2,
    arrowcolor: '#000000',
    font: {size:12, color:'#222222'},
    ax: 0,
    ay: 15
  },
  {
    x: 1,
    y: 1,
    xref: "x",
    yref: "y",
    text: "Pieni hyöty",
    showarrow: true,
    arrowhead: 3,
    arrowsize: 2,
    arrowcolor: '#000000',
    font: {size:12, color:'#000000'},
    ax: 0,
    ay: 15
  },
  {
    x: 2,
    y: 2,
    xref: "x",
    yref: "y",
    text: "Kohtuullinen hyöty",
    showarrow: true,
    arrowhead: 3,
    arrowsize: 2,
    arrowcolor: '#000000',
    font: {size:12, color:'#000000'},
    ax: 0,
    ay: 15
  },
  {
    x: 3,
    y: 3,
    xref: "x",
    yref: "y",
    text: "Suuri hyöty",
    showarrow: true,
    arrowhead: 3,
    arrowsize: 2,
    arrowcolor: '#000000',
    font: {size:12, color:'#ffffff'},
    ax: 0,
    ay: 15
  },
  {
    x: 4,
    y: 4,
    xref: "x",
    yref: "y",
    text: "Erittäin suuri hyöty",
    showarrow: true,
    arrowhead: 3,
    arrowsize: 2,
    arrowcolor: '#000000',
    font: {size:12, color:'#ffffff'},
    ax: 0,
    ay: 15
  }
];

const layout = {
  title: "Kokonaisarvio datan hyötypotentiaalista",
  annotations: dataAnnotations,
  margin: {
    t: 100,
    r: 20,
    b: 50,
    l: 230
  },
  xaxis: {
    ticks: "",
    side: "top"
  },
  yaxis: {
    ticks: "",
    ticksuffix: " ",
    width: 1500,
    height: 1500,
    autosize: true
  }
};

for (var i = 0; i < yValues.length; i++) {
  for (var j = 0; j < xValues.length; j++) {
    var currentValue = zValues[i][j];
    if (currentValue == 0.0) {
      var textColor = "white";
    } else if (currentValue == 20) {
      var textColor = "white";
    } else if (currentValue == 40) {
      var textColor = "black";
    } else if (currentValue == 60) {
      var textColor = "black";
    } else {
      var textColor = "black";
    }
    var result = {
      xref: "x1",
      yref: "y1",
      x: xValues[j],
      y: yValues[i],
      text: zValues[i][j],
      font: {
        family: "Arial",
        size: 12,
        color: "rgb(50, 171, 96)"
      },
      showarrow: false,
      font: {
        color: textColor
      }
    };
    layout.annotations.push(result);
  }
}

Plotly.newPlot("myDiv", data, layout, { showSendToCloud: false });

              
            
!
999px

Console