import bokeh
from bokeh.plotting import figure, show
from bokeh.io import output_file, output_notebook
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
url = "https://gist.githubusercontent.com/seankross/a412dfbd88b3db70b74b/raw/5f23f993cd87c283ce766e7ac6b329ee7cc2e1d1/mtcars.csv"
carsdf = pd.read_csv(url)
carsdf.head(3)
model mpg cyl disp hp drat wt qsec vs am gear carb
0 Mazda RX4 21 6 160 110 3.9 2.62 16.46 0 1 4 4
1 Mazda RX4 Wag 21 6 160 110 3.9 2.875 17.02 0 1 4 4
2 Datsun 710 22.8 4 108 93 3.85 2.32 18.61 1 1 4 1
p = figure(title="Simple line example", x_axis_label="wt", y_axis_label="mpg")
p.circle(carsdf['wt'], carsdf['mpg'])
show(p)
output_notebook()

(function(root) {
  function now() {
    return new Date();
  }

  var force = true;

  if (typeof root._bokeh_onload_callbacks === "undefined" || force === true) {
    root._bokeh_onload_callbacks = [];
    root._bokeh_is_loading = undefined;
  }

  var JS_MIME_TYPE = 'application/javascript';
  var HTML_MIME_TYPE = 'text/html';
  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';
  var CLASS_NAME = 'output_bokeh rendered_html';

  /**
   * Render data to the DOM node
   */
  function render(props, node) {
    var script = document.createElement("script");
    node.appendChild(script);
  }

  /**
   * Handle when an output is cleared or removed
   */
  function handleClearOutput(event, handle) {
    var cell = handle.cell;

    var id = cell.output_area._bokeh_element_id;
    var server_id = cell.output_area._bokeh_server_id;
    // Clean up Bokeh references
    if (id != null && id in Bokeh.index) {
      Bokeh.index[id].model.document.clear();
      delete Bokeh.index[id];
    }

    if (server_id !== undefined) {
      // Clean up Bokeh references
      var cmd = "from bokeh.io.state import curstate; print(curstate().uuid_to_server['" + server_id + "'].get_sessions()[0].document.roots[0]._id)";
      cell.notebook.kernel.execute(cmd, {
        iopub: {
          output: function(msg) {
            var id = msg.content.text.trim();
            if (id in Bokeh.index) {
              Bokeh.index[id].model.document.clear();
              delete Bokeh.index[id];
            }
          }
        }
      });
      // Destroy server and session
      var cmd = "import bokeh.io.notebook as ion; ion.destroy_server('" + server_id + "')";
      cell.notebook.kernel.execute(cmd);
    }
  }

  /**
   * Handle when a new output is added
   */
  function handleAddOutput(event, handle) {
    var output_area = handle.output_area;
    var output = handle.output;

    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only
    if ((output.output_type != "display_data") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {
      return
    }

    var toinsert = output_area.element.find("." + CLASS_NAME.split(' ')[0]);

    if (output.metadata[EXEC_MIME_TYPE]["id"] !== undefined) {
      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];
      // store reference to embed id on output_area
      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE]["id"];
    }
    if (output.metadata[EXEC_MIME_TYPE]["server_id"] !== undefined) {
      var bk_div = document.createElement("div");
      bk_div.innerHTML = output.data[HTML_MIME_TYPE];
      var script_attrs = bk_div.children[0].attributes;
      for (var i = 0; i < script_attrs.length; i++) {
        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);
        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent
      }
      // store reference to server id on output_area
      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE]["server_id"];
    }
  }

  function register_renderer(events, OutputArea) {

    function append_mime(data, metadata, element) {
      // create a DOM node to render to
      var toinsert = this.create_output_subarea(
        metadata,
        CLASS_NAME,
        EXEC_MIME_TYPE
      );
      this.keyboard_manager.register_events(toinsert);
      // Render to node
      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};
      render(props, toinsert[toinsert.length - 1]);
      element.append(toinsert);
      return toinsert
    }

    /* Handle when an output is cleared or removed */
    events.on('clear_output.CodeCell', handleClearOutput);
    events.on('delete.Cell', handleClearOutput);

    /* Handle when a new output is added */
    events.on('output_added.OutputArea', handleAddOutput);

    /**
     * Register the mime type and append_mime function with output_area
     */
    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {
      /* Is output safe? */
      safe: true,
      /* Index of renderer in `output_area.display_order` */
      index: 0
    });
  }

  // register the mime type if in Jupyter Notebook environment and previously unregistered
  if (root.Jupyter !== undefined) {
    var events = require('base/js/events');
    var OutputArea = require('notebook/js/outputarea').OutputArea;

    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {
      register_renderer(events, OutputArea);
    }
  }

  
  if (typeof (root._bokeh_timeout) === "undefined" || force === true) {
    root._bokeh_timeout = Date.now() + 5000;
    root._bokeh_failed_load = false;
  }

  var NB_LOAD_WARNING = {'data': {'text/html':
     "<div style='background-color: #fdd'>\n"+
     "<p>\n"+
     "BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \n"+
     "may be due to a slow or bad network connection. Possible fixes:\n"+
     "</p>\n"+
     "<ul>\n"+
     "<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\n"+
     "<li>use INLINE resources instead, as so:</li>\n"+
     "</ul>\n"+
     "<code>\n"+
     "from bokeh.resources import INLINE\n"+
     "output_notebook(resources=INLINE)\n"+
     "</code>\n"+
     "</div>"}};

  function display_loaded() {
    var el = document.getElementById(null);
    if (el != null) {
      el.textContent = "BokehJS is loading...";
    }
    if (root.Bokeh !== undefined) {
      if (el != null) {
        el.textContent = "BokehJS " + root.Bokeh.version + " successfully loaded.";
      }
    } else if (Date.now() < root._bokeh_timeout) {
      setTimeout(display_loaded, 100)
    }
  }


  function run_callbacks() {
    try {
      root._bokeh_onload_callbacks.forEach(function(callback) {
        if (callback != null)
          callback();
      });
    } finally {
      delete root._bokeh_onload_callbacks
    }
    console.debug("Bokeh: all callbacks have finished");
  }

  function load_libs(css_urls, js_urls, callback) {
    if (css_urls == null) css_urls = [];
    if (js_urls == null) js_urls = [];

    root._bokeh_onload_callbacks.push(callback);
    if (root._bokeh_is_loading > 0) {
      console.debug("Bokeh: BokehJS is being loaded, scheduling callback at", now());
      return null;
    }
    if (js_urls == null || js_urls.length === 0) {
      run_callbacks();
      return null;
    }
    console.debug("Bokeh: BokehJS not loaded, scheduling load and callback at", now());
    root._bokeh_is_loading = css_urls.length + js_urls.length;

    function on_load() {
      root._bokeh_is_loading--;
      if (root._bokeh_is_loading === 0) {
        console.debug("Bokeh: all BokehJS libraries/stylesheets loaded");
        run_callbacks()
      }
    }

    function on_error(url) {
      console.error("failed to load " + url);
    }

    for (let i = 0; i < css_urls.length; i++) {
      const url = css_urls[i];
      const element = document.createElement("link");
      element.onload = on_load;
      element.onerror = on_error.bind(null, url);
      element.rel = "stylesheet";
      element.type = "text/css";
      element.href = url;
      console.debug("Bokeh: injecting link tag for BokehJS stylesheet: ", url);
      document.body.appendChild(element);
    }

    const hashes = {"https://cdn.bokeh.org/bokeh/release/bokeh-2.3.2.min.js": "XypntL49z55iwGVUW4qsEu83zKL3XEcz0MjuGOQ9SlaaQ68X/g+k1FcioZi7oQAc", "https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.3.2.min.js": "bEsM86IHGDTLCS0Zod8a8WM6Y4+lafAL/eSiyQcuPzinmWNgNO2/olUF0Z2Dkn5i", "https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.3.2.min.js": "TX0gSQTdXTTeScqxj6PVQxTiRW8DOoGVwinyi1D3kxv7wuxQ02XkOxv0xwiypcAH"};

    for (let i = 0; i < js_urls.length; i++) {
      const url = js_urls[i];
      const element = document.createElement('script');
      element.onload = on_load;
      element.onerror = on_error.bind(null, url);
      element.async = false;
      element.src = url;
      if (url in hashes) {
        element.crossOrigin = "anonymous";
        element.integrity = "sha384-" + hashes[url];
      }
      console.debug("Bokeh: injecting script tag for BokehJS library: ", url);
      document.head.appendChild(element);
    }
  };

  function inject_raw_css(css) {
    const element = document.createElement("style");
    element.appendChild(document.createTextNode(css));
    document.body.appendChild(element);
  }

  
  var js_urls = ["https://cdn.bokeh.org/bokeh/release/bokeh-2.3.2.min.js", "https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.3.2.min.js", "https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.3.2.min.js"];
  var css_urls = [];
  

  var inline_js = [
    function(Bokeh) {
      Bokeh.set_log_level("info");
    },
    function(Bokeh) {
    
    
    }
  ];

  function run_inline_js() {
    
    if (root.Bokeh !== undefined || force === true) {
      
    for (var i = 0; i < inline_js.length; i++) {
      inline_js[i].call(root, root.Bokeh);
    }
    } else if (Date.now() < root._bokeh_timeout) {
      setTimeout(run_inline_js, 100);
    } else if (!root._bokeh_failed_load) {
      console.log("Bokeh: BokehJS failed to load within specified timeout.");
      root._bokeh_failed_load = true;
    } else if (force !== true) {
      var cell = $(document.getElementById(null)).parents('.cell').data().cell;
      cell.output_area.append_execute_result(NB_LOAD_WARNING)
    }

  }

  if (root._bokeh_is_loading === 0) {
    console.debug("Bokeh: BokehJS loaded, going straight to plotting");
    run_inline_js();
  } else {
    load_libs(css_urls, js_urls, function() {
      console.debug("Bokeh: BokehJS plotting callback run at", now());
      run_inline_js();
    });
  }
}(window));
null
(function(root) {
  function embed_document(root) {
    
  var docs_json = {"d7252b32-41db-4934-9d19-a97e2e1e8f75":{"defs":[],"roots":{"references":[{"attributes":{"below":[{"id":"1447"}],"center":[{"id":"1450"},{"id":"1454"}],"left":[{"id":"1451"}],"renderers":[{"id":"1472"},{"id":"1503"}],"title":{"id":"1437"},"toolbar":{"id":"1462"},"x_range":{"id":"1439"},"x_scale":{"id":"1443"},"y_range":{"id":"1441"},"y_scale":{"id":"1445"}},"id":"1436","subtype":"Figure","type":"Plot"},{"attributes":{"text":"Simple line example"},"id":"1437","type":"Title"},{"attributes":{"axis_label":"wt","formatter":{"id":"1496"},"major_label_policy":{"id":"1494"},"ticker":{"id":"1448"}},"id":"1447","type":"LinearAxis"},{"attributes":{"data_source":{"id":"1500"},"glyph":{"id":"1501"},"hover_glyph":null,"muted_glyph":null,"nonselection_glyph":{"id":"1502"},"view":{"id":"1504"}},"id":"1503","type":"GlyphRenderer"},{"attributes":{},"id":"1460","type":"HelpTool"},{"attributes":{"data":{"x":{"__ndarray__":"9ihcj8L1BEAAAAAAAAAHQI/C9ShcjwJAuB6F61G4CUCF61G4HoULQK5H4XoUrgtAj8L1KFyPDECF61G4HoUJQDMzMzMzMwlAhetRuB6FC0CF61G4HoULQEjhehSuRxBA16NwPQrXDUA9CtejcD0OQAAAAAAAABVAGARWDi2yFUDhehSuR2EVQJqZmZmZmQFA16NwPQrX+T9cj8L1KFz9P7gehetRuANAKVyPwvUoDEB7FK5H4XoLQLgehetRuA5Aw/UoXI/CDkD2KFyPwvX+Px+F61G4HgFAaZHtfD81+D9cj8L1KFwJQClcj8L1KAZAj8L1KFyPDEA9CtejcD0GQA==","dtype":"float64","order":"little","shape":[32]},"y":{"__ndarray__":"AAAAAAAANUAAAAAAAAA1QM3MzMzMzDZAZmZmZmZmNUAzMzMzM7MyQJqZmZmZGTJAmpmZmZmZLEBmZmZmZmY4QM3MzMzMzDZAMzMzMzMzM0DNzMzMzMwxQGZmZmZmZjBAzczMzMxMMUBmZmZmZmYuQM3MzMzMzCRAzczMzMzMJEBmZmZmZmYtQDMzMzMzM0BAZmZmZmZmPkAzMzMzM/NAQAAAAAAAgDVAAAAAAAAAL0BmZmZmZmYuQJqZmZmZmSpAMzMzMzMzM0DNzMzMzEw7QAAAAAAAADpAZmZmZmZmPkCamZmZmZkvQDMzMzMzszNAAAAAAAAALkBmZmZmZmY1QA==","dtype":"float64","order":"little","shape":[32]}},"selected":{"id":"1498"},"selection_policy":{"id":"1499"}},"id":"1469","type":"ColumnDataSource"},{"attributes":{},"id":"1455","type":"PanTool"},{"attributes":{},"id":"1445","type":"LinearScale"},{"attributes":{"fill_color":{"value":"#1f77b4"},"line_color":{"value":"#1f77b4"},"x":{"field":"x"},"y":{"field":"y"}},"id":"1501","type":"Circle"},{"attributes":{"active_multi":null,"tools":[{"id":"1455"},{"id":"1456"},{"id":"1457"},{"id":"1458"},{"id":"1459"},{"id":"1460"}]},"id":"1462","type":"Toolbar"},{"attributes":{},"id":"1498","type":"Selection"},{"attributes":{},"id":"1439","type":"DataRange1d"},{"attributes":{},"id":"1491","type":"AllLabels"},{"attributes":{},"id":"1515","type":"Selection"},{"attributes":{},"id":"1458","type":"SaveTool"},{"attributes":{"axis":{"id":"1451"},"dimension":1,"ticker":null},"id":"1454","type":"Grid"},{"attributes":{},"id":"1443","type":"LinearScale"},{"attributes":{},"id":"1441","type":"DataRange1d"},{"attributes":{"fill_alpha":{"value":0.1},"fill_color":{"value":"#1f77b4"},"line_alpha":{"value":0.1},"line_color":{"value":"#1f77b4"},"x":{"field":"x"},"y":{"field":"y"}},"id":"1502","type":"Circle"},{"attributes":{"overlay":{"id":"1461"}},"id":"1457","type":"BoxZoomTool"},{"attributes":{},"id":"1499","type":"UnionRenderers"},{"attributes":{"axis_label":"mpg","formatter":{"id":"1493"},"major_label_policy":{"id":"1491"},"ticker":{"id":"1452"}},"id":"1451","type":"LinearAxis"},{"attributes":{},"id":"1459","type":"ResetTool"},{"attributes":{"source":{"id":"1500"}},"id":"1504","type":"CDSView"},{"attributes":{"bottom_units":"screen","fill_alpha":0.5,"fill_color":"lightgrey","left_units":"screen","level":"overlay","line_alpha":1.0,"line_color":"black","line_dash":[4,4],"line_width":2,"right_units":"screen","syncable":false,"top_units":"screen"},"id":"1461","type":"BoxAnnotation"},{"attributes":{},"id":"1516","type":"UnionRenderers"},{"attributes":{"fill_color":{"value":"#1f77b4"},"line_color":{"value":"#1f77b4"},"x":{"field":"x"},"y":{"field":"y"}},"id":"1470","type":"Circle"},{"attributes":{"axis":{"id":"1447"},"ticker":null},"id":"1450","type":"Grid"},{"attributes":{},"id":"1494","type":"AllLabels"},{"attributes":{},"id":"1448","type":"BasicTicker"},{"attributes":{"data_source":{"id":"1469"},"glyph":{"id":"1470"},"hover_glyph":null,"muted_glyph":null,"nonselection_glyph":{"id":"1471"},"view":{"id":"1473"}},"id":"1472","type":"GlyphRenderer"},{"attributes":{},"id":"1456","type":"WheelZoomTool"},{"attributes":{"source":{"id":"1469"}},"id":"1473","type":"CDSView"},{"attributes":{},"id":"1496","type":"BasicTickFormatter"},{"attributes":{"fill_alpha":{"value":0.1},"fill_color":{"value":"#1f77b4"},"line_alpha":{"value":0.1},"line_color":{"value":"#1f77b4"},"x":{"field":"x"},"y":{"field":"y"}},"id":"1471","type":"Circle"},{"attributes":{},"id":"1452","type":"BasicTicker"},{"attributes":{},"id":"1493","type":"BasicTickFormatter"},{"attributes":{"data":{"x":{"__ndarray__":"9ihcj8L1BEAAAAAAAAAHQI/C9ShcjwJAuB6F61G4CUCF61G4HoULQK5H4XoUrgtAj8L1KFyPDECF61G4HoUJQDMzMzMzMwlAhetRuB6FC0CF61G4HoULQEjhehSuRxBA16NwPQrXDUA9CtejcD0OQAAAAAAAABVAGARWDi2yFUDhehSuR2EVQJqZmZmZmQFA16NwPQrX+T9cj8L1KFz9P7gehetRuANAKVyPwvUoDEB7FK5H4XoLQLgehetRuA5Aw/UoXI/CDkD2KFyPwvX+Px+F61G4HgFAaZHtfD81+D9cj8L1KFwJQClcj8L1KAZAj8L1KFyPDEA9CtejcD0GQA==","dtype":"float64","order":"little","shape":[32]},"y":{"__ndarray__":"AAAAAAAANUAAAAAAAAA1QM3MzMzMzDZAZmZmZmZmNUAzMzMzM7MyQJqZmZmZGTJAmpmZmZmZLEBmZmZmZmY4QM3MzMzMzDZAMzMzMzMzM0DNzMzMzMwxQGZmZmZmZjBAzczMzMxMMUBmZmZmZmYuQM3MzMzMzCRAzczMzMzMJEBmZmZmZmYtQDMzMzMzM0BAZmZmZmZmPkAzMzMzM/NAQAAAAAAAgDVAAAAAAAAAL0BmZmZmZmYuQJqZmZmZmSpAMzMzMzMzM0DNzMzMzEw7QAAAAAAAADpAZmZmZmZmPkCamZmZmZkvQDMzMzMzszNAAAAAAAAALkBmZmZmZmY1QA==","dtype":"float64","order":"little","shape":[32]}},"selected":{"id":"1515"},"selection_policy":{"id":"1516"}},"id":"1500","type":"ColumnDataSource"}],"root_ids":["1436"]},"title":"Bokeh Application","version":"2.3.2"}};
  var render_items = [{"docid":"d7252b32-41db-4934-9d19-a97e2e1e8f75","root_ids":["1436"],"roots":{"1436":"6d5a3644-00bf-4d09-9dbc-878bc5dbf72c"}}];
  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);

  }
  if (root.Bokeh !== undefined) {
    embed_document(root);
  } else {
    var attempts = 0;
    var timer = setInterval(function(root) {
      if (root.Bokeh !== undefined) {
        clearInterval(timer);
        embed_document(root);
      } else {
        attempts++;
        if (attempts > 100) {
          clearInterval(timer);
          console.log("Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing");
        }
      }
    }, 10, root)
  }
})(window);