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>
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
  <div id="myDiv" class="plotly" align="center" style="width:800px; height:500px;"></div>
  
<p id="demo"></p>
<p id="demo2"></p>
</body>
              
            
!

CSS

              
                @media only screen and (max-width: 699px) {
    /* For tablets: */
.hovertext text{

        font-family: Helvetica !important;

        font-size:8px !important;
  } 
}

@media only screen and (min-width: 700px) {
    /* For tablets: */
.hovertext text{

        font-family: Helvetica !important;

        font-size:20px !important;
  } 
}
              
            
!

JS

              
                var d3 = Plotly.d3; 
var WIDTH_IN_PERCENT_OF_PARENT = 80,
    HEIGHT_IN_PERCENT_OF_PARENT = 60;

var gd3 = d3.select("div[id='myDiv']")
  .style({
    width: WIDTH_IN_PERCENT_OF_PARENT + '%',
    'margin-left': (100 - WIDTH_IN_PERCENT_OF_PARENT) / 2 + '%',
    height: HEIGHT_IN_PERCENT_OF_PARENT + 'vh',
    'margin-top': (100 - HEIGHT_IN_PERCENT_OF_PARENT) / 2 + 'vh'
});

var my_Div = gd3.node();
var figure = {
  "frames": [
      //Frame for narrow screens
            {"data": [], 
             "layout":{
               "xaxis": { 
                         "dtick": 2,
                          "tickfont": {"size":8}
             },
               "images": [
                {
                  "x": 1,
                  "y": 1,
                  "sizex": 0.2,
                  "sizey": 0.2,
                  // "source": "https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/vox.png",
                  "source": "https://images.plot.ly/language-icons/api-home/python-logo.png", 
                  
                  // "source":"https://s3.amazonaws.com/org-emissionsindex/content/CMU_wordmarks/CMU_Logo_Stack_Red.png",
                  "xanchor": "right",
                  "xref": "paper",
                  "yanchor": "bottom",
                  "yref": "paper"
                }
              ],
            "annotations":[
              {"text": "Small",
               "yref":"paper",
               "xref":"paper",
               "y": .25, 
               "x": .8, 
               "showarrow": false,
               "font": {"size":10}
                    }
                          ]
                      },
             "name": "workspace-breakpoint-0"
             },
    //Frame for wider screens
             {"data": [], 
             "layout":{
               "xaxis": { 
                         "dtick": 1,
                          "tickfont": {"size":18}
             },
            "images": [
                {
                  "x": 1,
                  "y": 1,
                  "sizex": 0.2,
                  "sizey": 0.2,
                  "source": "https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/vox.png",
                  // "source":"https://s3.amazonaws.com/org-emissionsindex/content/CMU_wordmarks/CMU_Logo_Stack_Red.png",
                  "xanchor": "right",
                  "xref": "paper",
                  "yanchor": "bottom",
                  "yref": "paper"
                }
              ],
            "annotations":[
              {"text": "Normal",
               "yref":"paper",
               "xref":"paper",
               "y": .25, 
               "x": .2, 
               "showarrow": false,
               "font": {"size":14}
                    }
                          ]
                      },
             "name": "workspace-breakpoint-1"
             }
              ],
  // Starting layout
  "layout":{
               "xaxis": {"dtick": 1,
                          "tickfont": {"size":18}
                        }, 
            "images": [
                {
                  "x": .5,
                  "y": 1,
                  "sizex": 0.2,
                  "sizey": 0.2,
                  // "source": "https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/vox.png",
                  "source":"https://s3.amazonaws.com/org-emissionsindex/content/CMU_wordmarks/CMU_Logo_Stack_Red.png",
                  "xref": "paper",
                  "yref": "paper"
                }
              ],
            "annotations":[
              {"text": "Normal",
               "yref":"paper",
               "xref":"paper",
               "y": .25, 
               "x": .2, 
               "showarrow": false,
               "font": {"size":14}
                    }
            ],
           "breakpoints": [
            {"frame": "workspace-breakpoint-0", 
             "type": "width", 
              "range": [0, 700]
            }
        ], 
                      },
  "data":[{"x": [1,2,3,4,5],
          "y": [5,6,4,7,5],
         "type":"scatter",
         "mode":"lines"}]
              
        }


Plotly.plot(my_Div, 
           {data : figure.data,
           layout : figure.layout});

//Just checking to see if I can access the breakpoint range
var breakpoint = figure.layout.breakpoints[0].range[1]

//This is the layout data for the frame I want to use with small screen sizes, and the normal layout
var small_layout = figure.frames[0].layout
var normal_layout = figure.frames[1].layout //figure.layout

window.onresize = function() {
  var ww = window.innerWidth
  var wh = window.innerHeight
  
  Plotly.Plots.resize( my_Div )

  document.getElementById("demo").innerHTML = window.innerWidth

  // Assign the appropriate layout to relayoutObject
  if (ww < breakpoint) {
    relayoutObject = small_layout
    } 

  if (ww >= breakpoint) {
    relayoutObject = normal_layout //figure.layout
                } 

  // find breakpoint that corresponds to new window width, height
  Plotly.relayout( my_Div, relayoutObject)
  
}
              
            
!
999px

Console