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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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>
  
  <div id="graph"></div>
  <script>
    <!-- JAVASCRIPT CODE GOES HERE -->
  </script>
</body>
              
            
!

CSS

              
                
              
            
!

JS

              
                // Original Trace to select (heatmap)
var orgTrace = {
    z: [[1, 20, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, -10, 20]],
    x: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
    y: ['Morning', 'Afternoon', 'Evening'],
    type: 'heatmap'
  };
// empty trace, will be filled with selected data
var selectedTrace = {x: [],
                     y: []};

var data = [orgTrace, selectedTrace];

// OPTIONAL: define a final height value and
// set height to a ratio of this val to keep original
// trace height consistent when selected trace is added 
// (may want to define margins too for better consistency)
var height = 1000;
var layout = {height:height*.6};

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

var myPlot = document.getElementById('graph');

myPlot.on('plotly_click', function(data){
	yCoordinate = data.points[0].pointNumber[0];
	xCoordinate = data.points[0].pointNumber[1];
	    			
	yArray = data.points[0].fullData.z[yCoordinate];	
	xArray = data.points[0].fullData.x;
	
	// add data to selected trace (index 1)
	// set yaxis to y2 they will share the x axis
	var data_update0 = {colorbar:{len:0.6, y:.7}};
	var data_update1 = {x: [xArray],
					        y: [yArray],
							  yaxis: 'y2'};
	// define new height and domains for the 2 y axis 
	var layout_update = {height: height, 
								yaxis: {domain:[.4, 1]}, 
								yaxis2:{domain:[0, .3]}};
	// update (div, data update, layout update, trace(s) index for data update)
	Plotly.restyle('graph', data_update0, 0);
	Plotly.update('graph', data_update1, layout_update, 1);	    			
});
              
            
!
999px

Console