Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


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


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.


Auto Save

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.


  <!-- Plotly.js -->
  <script src=""></script>

  <div id="graph"></div>




                // 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);