<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <atom:link href="http://kitchingroup.cheme.cmu.edu/blog/feed/index.xml" rel="self" type="application/rss+xml" />
    <title>The Kitchin Research Group</title>
    <link>https://kitchingroup.cheme.cmu.edu/blog</link>
    <description>Chemical Engineering at Carnegie Mellon University</description>
    <pubDate>Sat, 01 Nov 2025 13:47:46 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    
    <item>
      <title>A new and improved Emacs gnuplot DSL</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2017/05/05/A-new-and-improved-Emacs-gnuplot-DSL</link>
      <pubDate>Fri, 05 May 2017 10:26:00 EDT</pubDate>
      <category><![CDATA[lisp]]></category>
      <category><![CDATA[emacs]]></category>
      <category><![CDATA[plotting]]></category>
      <guid isPermaLink="false">SKkqBSazd8jxa4md_x_2Xt31v8A=</guid>
      <description>A new and improved Emacs gnuplot DSL</description>
      <content:encoded><![CDATA[


&lt;p&gt;
A significant limitation of the	&lt;a href="http://kitchingroup.cheme.cmu.edu/blog/2017/05/04/An-emacs-lisp-dsl-for-gnuplot/"&gt;previous&lt;/a&gt; DSL I wrote is that all the plotting commands have to go in one macro. It would be nice to accumulate them in different forms, and when you want to run them all. A classic way to do that in Emacs lisp is to make a global variable, e.g. &lt;code&gt;*gnuplot-cmds*&lt;/code&gt; and append commands to it. Then when you want to, run the commands.
&lt;/p&gt;

&lt;p&gt;
A more modern approach is to use a closure to encapsulate the commands. Here is a &lt;a href="http://letoverlambda.com"&gt;"let over lambda"&lt;/a&gt; that defines a few functions that encapsulate an enclosed variable gnuplot-commands. We define one function to add commands to the list of commands, one to clear the commands, one to generate the gnuplot script as a string, and one to run the program. The enclosed variable &lt;code&gt;gnuplot-commands&lt;/code&gt; is basically only accessible by these functions. It is encapsulated, similar to if we defined a class in Python then made an instance of it with an attribute that was accessible only be instance methods. On one hand, this "protects" the variable, and keeps it out of the global namespace. On the other hand, we lose the documentation that would have come with a defvar, and we have to define a function to access the contents of that variable.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((gnuplot-commands '(&lt;span style="color: #008000;"&gt;"set terminal qt"&lt;/span&gt;)))

  (&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;gnuplot-add-cmd&lt;/span&gt; (s)
    &lt;span style="color: #036A07;"&gt;"Append the command S to gnuplot-cmds."&lt;/span&gt;
    (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; gnuplot-commands (append gnuplot-commands (list s))))

  (&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;gnuplot-clear&lt;/span&gt; ()
    (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; gnuplot-commands '(&lt;span style="color: #008000;"&gt;"set terminal qt"&lt;/span&gt;)))

  (&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;gnuplot-script&lt;/span&gt; ()
    (s-join &lt;span style="color: #008000;"&gt;"\n"&lt;/span&gt; gnuplot-commands)))
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
gnuplot-script

&lt;/pre&gt;

&lt;p&gt;
To run the commands, we define this function. It does not need to be in the closure because it only accesses the commands through functions we defined in the closure.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;gnuplot-show&lt;/span&gt; ()
    (&lt;span style="color: #0000FF;"&gt;let*&lt;/span&gt; ((temporary-file-directory &lt;span style="color: #008000;"&gt;"."&lt;/span&gt;)
           (cmdfile (make-temp-file &lt;span style="color: #008000;"&gt;"gnuplot-cmds-"&lt;/span&gt; nil &lt;span style="color: #008000;"&gt;".gpl"&lt;/span&gt;))
           (shellcmd (format &lt;span style="color: #008000;"&gt;"gnuplot --persist -c \"%s\""&lt;/span&gt; cmdfile))
           (cmds (gnuplot-script)))
      (&lt;span style="color: #0000FF;"&gt;with-temp-file&lt;/span&gt; cmdfile
        (insert cmds))
      (shell-command shellcmd)
      (delete-file cmdfile)
      cmds))
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
gnuplot-show

&lt;/pre&gt;

&lt;p&gt;
Last time I noted I had a new idea for the DSL syntax that would give us more flexibility to inject variables and code into the DSL. The idea is to use keywords, symbols that start with :, to indicate they should be replaced by the value of the non-keyword symbol in the environment, and for any form that starts with : to evaluate that form. So, (: - 5 4) would get replaced by 1. Here is the new macro for that.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defmacro&lt;/span&gt; &lt;span style="color: #006699;"&gt;kargs&lt;/span&gt; (&lt;span style="color: #6434A3;"&gt;&amp;amp;rest&lt;/span&gt; args)
  &lt;span style="color: #036A07;"&gt;"Convert symbols to strings, quote strings, and (expr) to what they evaluate to."&lt;/span&gt;
  `(s-join &lt;span style="color: #008000;"&gt;" "&lt;/span&gt; (list ,@(cl-mapcan
                        (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (s)
                          (list
                           (&lt;span style="color: #0000FF;"&gt;cond&lt;/span&gt;
                            ((keywordp s)
                             (format &lt;span style="color: #008000;"&gt;"%s"&lt;/span&gt;
                                     (symbol-value (intern (substring (symbol-name s) 1)))))
                            ((symbolp s)
                             (symbol-name s))
                            ((stringp s)
                             (format &lt;span style="color: #008000;"&gt;"\"%s\""&lt;/span&gt; s))
                            ((&lt;span style="color: #0000FF;"&gt;and&lt;/span&gt; (listp s) (eq : (car s)))
                             `(&lt;span style="color: #0000FF;"&gt;with-output-to-string&lt;/span&gt;
                                (princ ,(cdr s))))
                            (t
                             (format &lt;span style="color: #008000;"&gt;"%s"&lt;/span&gt; s)))))
                        args))))
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
kargs

&lt;/pre&gt;

&lt;p&gt;
Now, our gnuplot macro is simpler, since all it does is add commands to the list. If the form is a string, we add it as is, if the form starts with (: stuff) we evaluate the cdr of the form, and otherwise, we pass the form contents to the kargs macro for processing.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defmacro&lt;/span&gt; &lt;span style="color: #006699;"&gt;gnuplot&lt;/span&gt; (&lt;span style="color: #6434A3;"&gt;&amp;amp;rest&lt;/span&gt; forms)
  `(&lt;span style="color: #0000FF;"&gt;loop&lt;/span&gt; for s in (list ,@(mapcar (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (x)
                                    (&lt;span style="color: #0000FF;"&gt;cond&lt;/span&gt;
                                     ((stringp x)
                                      x)
                                     ((&lt;span style="color: #0000FF;"&gt;and&lt;/span&gt; (listp x) (eq : (car x)))
                                      `,(cdr x))
                                     (t
                                      `(kargs ,@x))))
                                  forms))
         do (gnuplot-add-cmd s)))
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
gnuplot

&lt;/pre&gt;

&lt;p&gt;
What did that gain us? First, we can break up a script so we can talk about it, maybe do some calculations, etc&amp;#x2026; Let's look at the example at &lt;a href="http://gnuplot.sourceforge.net/demo/linkedaxes.html"&gt;http://gnuplot.sourceforge.net/demo/linkedaxes.html&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
We can start with the basic settings.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(gnuplot-clear)

(gnuplot
 (set terminal png)
 (set output &lt;span style="color: #008000;"&gt;"linkedaxes.png"&lt;/span&gt;)
 (set encoding utf8)
 (set key outside Left)
 (set bmargin 5)
 (set tmargin 6)
 (set style data lines)
 (set tics in)
 (set ticslevel 0.5)
 (set xlabel  &lt;span style="color: #008000;"&gt;"X-ray energy in eV"&lt;/span&gt;)

 (set format y  \'%5.1fe\')
 (set title &lt;span style="color: #008000;"&gt;" Anomalous scattering factors "&lt;/span&gt;)
 (set xrange  [9000:14400])
 (set offset 0\,0\,1.0\,0)
 (set xtics nomirror)
 (set link x via 12398./x inverse 12398./x)

 (set x2label  &lt;span style="color: #008000;"&gt;"X-ray wavelength in &amp;#197;"&lt;/span&gt;)
 (set x2tics 0.1  format &lt;span style="color: #008000;"&gt;"%.1f &amp;#197;"&lt;/span&gt; nomirror))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
We need to download some data files. We can do that, and add another line to the gnuplot script. The escaping on the quotes and commas is especially tedious in this one ;) but, we don't need those pesky line-continuations here.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(shell-command &lt;span style="color: #008000;"&gt;"wget http://skuld.bmsc.washington.edu/scatter/data/Br.dat"&lt;/span&gt;)
(shell-command &lt;span style="color: #008000;"&gt;"wget http://skuld.bmsc.washington.edu/scatter/data/Ta.dat"&lt;/span&gt;)


(gnuplot
 (plot &lt;span style="color: #008000;"&gt;"Br.dat"&lt;/span&gt; volatile using 1:3 title \'Br f\"\'  lt 1 lw 3\, \'\' volatile using 1:2 title &lt;span style="color: #008000;"&gt;"Br f'"&lt;/span&gt;  lt 1 lw 1\,
       &lt;span style="color: #008000;"&gt;"Ta.dat"&lt;/span&gt; volatile using 1:3 title \'Ta f\"\' lt 2 lw 3\, \'\' volatile using 1:2 title \"Ta f\'\"  lt 2 lw 1))

(gnuplot-script)
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
set terminal qt
set terminal png
set output "linkedaxes.png"
set encoding utf8
set key outside Left
set bmargin 5
set tmargin 6
set style data lines
set tics in
set ticslevel 0.5
set xlabel "X-ray energy in eV"
set format y '%5.1fe'
set title " Anomalous scattering factors "
set xrange [9000:14400]
set offset 0,0,1.0,0
set xtics nomirror
set link x via 12398./x inverse 12398./x
set x2label "X-ray wavelength in Å"
set x2tics 0.1 format "%.1f Å" nomirror
plot "Br.dat" volatile using 1:3 title 'Br f"' lt 1 lw 3, '' volatile using 1:2 title "Br f'" lt 1 lw 1, "Ta.dat" volatile using 1:3 title 'Ta f"' lt 2 lw 3, '' volatile using 1:2 title "Ta f'" lt 2 lw 1
&lt;/pre&gt;

&lt;p&gt;
Finally, we can set the output to png, and run our program.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(gnuplot-show)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Looks good.
&lt;/p&gt;



&lt;p&gt;
&lt;img src="/media/linkedaxes.png"&gt; 
&lt;/p&gt;

&lt;p&gt;
What about the fancy keyword formatting? Here is an example of that in action. :term gets replaced by the term variable, :png gets replaced by the filename, and :x is replaced by 4.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(gnuplot-clear)
(&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((x 4)
      (term &lt;span style="color: #008000;"&gt;"png"&lt;/span&gt;)
      (png &lt;span style="color: #008000;"&gt;"\"polar.png\""&lt;/span&gt;))
  (gnuplot
   (set terminal &lt;span style="color: #006FE0;"&gt;:term&lt;/span&gt;)
   (set output &lt;span style="color: #006FE0;"&gt;:png&lt;/span&gt;)
   (set polar)
   (set dummy t)
   (plot sin\( &lt;span style="color: #006FE0;"&gt;:x&lt;/span&gt; *t\) \,cos\( &lt;span style="color: #006FE0;"&gt;:x&lt;/span&gt; *t\))
   (set offset 0\,0\,0\,0)))

(gnuplot-show)
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
set terminal qt
set terminal png
set output "polar.png"
set polar
set dummy t
plot sin( 4 *t) ,cos( 4 *t)
set offset 0,0,0,0

&lt;/pre&gt;

&lt;p&gt;
&lt;img src="/media/polar.png"&gt; 
&lt;/p&gt;

&lt;p&gt;
There are a few nuances I didn't expect. First, you have to escape the parentheses in this case because otherwise it looks like a form that will be ignored. Second, you have to quote the string to get quotes into the gnuplot script. Third, there has to be a space before and after the keywords for emacs to parse it correctly and do the substitution.
&lt;/p&gt;

&lt;p&gt;
Let's look at one last example that uses the (: form). We reproduce a figure from &lt;a href="http://gnuplot.sourceforge.net/demo/transparent_solids.html"&gt;http://gnuplot.sourceforge.net/demo/transparent_solids.html&lt;/a&gt; here.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(gnuplot-clear)
(gnuplot
 (set terminal pngcairo  background &lt;span style="color: #008000;"&gt;"#ffffff"&lt;/span&gt; enhanced font &lt;span style="color: #008000;"&gt;"arial,9"&lt;/span&gt; fontscale 1.0 size 512\, 384 )
 (set output &lt;span style="color: #008000;"&gt;"transparent-solids.png"&lt;/span&gt;)
 &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;construct the title&lt;/span&gt;
 (set title (: format &lt;span style="color: #008000;"&gt;"\"%s\""&lt;/span&gt; (concat &lt;span style="color: #008000;"&gt;"Interlocking Tori - PM3D surface"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"with depth sorting and transparency"&lt;/span&gt;)))

 &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;use lisp code to create a gnuplot command&lt;/span&gt;
 (: concat &lt;span style="color: #008000;"&gt;"unset"&lt;/span&gt; &lt;span style="color: #008000;"&gt;" "&lt;/span&gt; &lt;span style="color: #008000;"&gt;"border"&lt;/span&gt;)

 (unset key)
 (set object 1 rect from screen 0\, 0\, 0 to screen 1\, 1\, 0 behind)
 (set object 1 rect fc  rgb \"gray\"  fillstyle solid 1.0  border -1)
 (set view 64\, 345\, 1.24375\, 0.995902)
 (set isosamples 50\, 20)
 (unset xtics)
 (unset ytics)
 (unset ztics)
 (set dummy u\,v)
 (set parametric)
 (set urange [ -pi : pi ])
 (set vrange [ -pi : pi ])

 (set style fill  transparent solid 0.30 border)
 (set pm3d depthorder)
 (set palette rgbformulae 8\, 9\, 7)
 (set pm3d interpolate 1\,1 flush begin noftriangles border lt black linewidth 0.500 dashtype solid corners2color mean)
 (set colorbox vertical origin screen 0.9\, 0.2\, 0 size screen 0.05\, 0.6\, 0 front  noinvert bdefault)

 (splot (: concat &lt;span style="color: #008000;"&gt;"cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with pm3d,"&lt;/span&gt;
           &lt;span style="color: #008000;"&gt;"1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with pm3d"&lt;/span&gt;)))
(gnuplot-show)
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
set terminal qt
set terminal pngcairo background "#ffffff" enhanced font "arial,9" fontscale 1.0 size 512, 384
set output "transparent-solids.png"
set title "Interlocking Tori - PM3D surfacewith depth sorting and transparency"
unset border
unset key
set object 1 rect from screen 0, 0, 0 to screen 1, 1, 0 behind
set object 1 rect fc rgb "gray" fillstyle solid 1.0 border -1
set view 64, 345, 1.24375, 0.995902
set isosamples 50, 20
unset xtics
unset ytics
unset ztics
set dummy u,v
set parametric
set urange [-pi : pi]
set vrange [-pi : pi]
set style fill transparent solid 0.3 border
set pm3d depthorder
set palette rgbformulae 8, 9, 7
set pm3d interpolate 1,1 flush begin noftriangles border lt black linewidth 0.5 dashtype solid corners2color mean
set colorbox vertical origin screen 0.9, 0.2, 0 size screen 0.05, 0.6, 0 front noinvert bdefault
splot cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with pm3d,1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with pm3d
&lt;/pre&gt;


&lt;p&gt;
&lt;img src="/media/transparent-solids.png"&gt; 
&lt;/p&gt;

&lt;p&gt;
Overall this seems like an improvement to the DSL. I didn't invent the idea of reusing keywords this way out of the blue. In On Lisp, Paul graham uses "special" variable names in Chapter 18, where he shows how to use gensyms for special purposes, and also variables with special names like ?x. Even Emacs is using a variation of this idea. Check out this &lt;a href="http://endlessparentheses.com/new-on-elpa-and-in-emacs-25-1-let-alist.html"&gt;new let-alist&lt;/a&gt; macro:
&lt;/p&gt;


&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;let-alist&lt;/span&gt; '((x . 5))
  (+ 1 .x))
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
6

&lt;/pre&gt;

&lt;p&gt;
There is a special variable inside the body that is a dot-name. The macro expands to provide a value for that symbol. I wonder if I should have tried to use an approach like this instead. Maybe another day. After I read and study the four defuns and single defmacro that make this possible!
&lt;/p&gt;

&lt;p&gt;
You can see here what happens:
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(macroexpand '(let-alist '((x . 5))
  (+ 1 .x)))
&lt;/pre&gt;
&lt;/div&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt;
    ((alist
      '((x . 5))))
  (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((\.x (cdr (assq 'x alist))))
    (+ 1 \.x)))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
The macro builds up an internal alist for the dot-names.
&lt;/p&gt;
&lt;p&gt;Copyright (C) 2018 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;
&lt;p&gt;&lt;a href="/org/2017/05/05/A-new-and-improved-Emacs-gnuplot-DSL.org"&gt;org-mode source&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Org-mode version = 9.1.6&lt;/p&gt;
]]></content:encoded>
    </item>
    <item>
      <title>An emacs-lisp dsl for gnuplot</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2017/05/04/An-emacs-lisp-dsl-for-gnuplot</link>
      <pubDate>Thu, 04 May 2017 19:33:55 EDT</pubDate>
      <category><![CDATA[lisp]]></category>
      <category><![CDATA[emacs]]></category>
      <category><![CDATA[plotting]]></category>
      <guid isPermaLink="false">0UZjXdfBOloIK7bnw4odvEI2ep0=</guid>
      <description>An emacs-lisp dsl for gnuplot</description>
      <content:encoded><![CDATA[


&lt;div id="table-of-contents"&gt;
&lt;h2&gt;Table of Contents&lt;/h2&gt;
&lt;div id="text-table-of-contents"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#orge24f7e9"&gt;1. Embedding Python or gnuplot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#orgfe7800b"&gt;2. An alternative approach using a DSL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#orga773a9d"&gt;3. Summary&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
Plotting is a pretty general feature we need in scientific work. In this post we examine a way we could get at least minimal plotting into Emacs-lisp with as lispy a syntax as reasonable.
&lt;/p&gt;

&lt;div id="outline-container-orge24f7e9" class="outline-2"&gt;
&lt;h2 id="orge24f7e9"&gt;&lt;span class="section-number-2"&gt;1&lt;/span&gt; Embedding Python or gnuplot&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;
&lt;p&gt;
With org-mode we can fluidly integrate many languages in one document. That is not the goal here, where I want to integrate plotting into a program. You certainly could go this route to embed python programs in your lisp programs for plotting.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;python&lt;/span&gt; (code)
  (&lt;span style="color: #0000FF;"&gt;let*&lt;/span&gt; ((temporary-file-directory &lt;span style="color: #008000;"&gt;"."&lt;/span&gt;)
        (tmpfile (make-temp-file &lt;span style="color: #008000;"&gt;"py-"&lt;/span&gt; nil &lt;span style="color: #008000;"&gt;".py"&lt;/span&gt;)))
    (&lt;span style="color: #0000FF;"&gt;with-temp-file&lt;/span&gt; tmpfile
      (insert code))
    (shell-command-to-string (format &lt;span style="color: #008000;"&gt;"python %s"&lt;/span&gt; tmpfile))))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Here is that function in action.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(python &lt;span style="color: #008000;"&gt;"import matplotlib.pyplot as plt&lt;/span&gt;
&lt;span style="color: #008000;"&gt;import numpy as np&lt;/span&gt;
&lt;span style="color: #008000;"&gt;x = np.linspace(0, 1)&lt;/span&gt;
&lt;span style="color: #008000;"&gt;y = np.exp(x)&lt;/span&gt;
&lt;span style="color: #008000;"&gt;plt.plot(x, y, label='data')&lt;/span&gt;
&lt;span style="color: #008000;"&gt;plt.title('A Title')&lt;/span&gt;
&lt;span style="color: #008000;"&gt;plt.xlim([0, 1])&lt;/span&gt;
&lt;span style="color: #008000;"&gt;plt.ylim([1, 2.75])&lt;/span&gt;
&lt;span style="color: #008000;"&gt;plt.xlabel('x')&lt;/span&gt;
&lt;span style="color: #008000;"&gt;plt.ylabel('y')&lt;/span&gt;
&lt;span style="color: #008000;"&gt;plt.legend()&lt;/span&gt;
&lt;span style="color: #008000;"&gt;plt.savefig('figpy.png')"&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
And the corresponding figure:
&lt;img src="/media/figpy.png"&gt; 
&lt;/p&gt;

&lt;p&gt;
This is irritating for a few reasons. One is it is annoying to write python programs in string form; you don't get much editor support for indentation or syntax highlighting, and you have to be careful with quotes. It is not that easy to switch that snippet to Python mode either. You are pretty limited in writing programs that expand and modify the code too. Basically you have to do that all by string manipulation.
&lt;/p&gt;

&lt;p&gt;
Along these lines, you could imagine a gnuplot function. It ends up not being much better.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;gnuplot&lt;/span&gt; (cmds)
  (&lt;span style="color: #0000FF;"&gt;let*&lt;/span&gt; ((temporary-file-directory &lt;span style="color: #008000;"&gt;"."&lt;/span&gt;)
         (cmdfile (make-temp-file &lt;span style="color: #008000;"&gt;"gnuplot-cmds-"&lt;/span&gt; nil &lt;span style="color: #008000;"&gt;".gpl"&lt;/span&gt;))
         (shellcmd (format &lt;span style="color: #008000;"&gt;"gnuplot --persist -c \"%s\""&lt;/span&gt; cmdfile)))
    (&lt;span style="color: #0000FF;"&gt;with-temp-file&lt;/span&gt; cmdfile
      (insert cmds))
    (shell-command shellcmd)
    (delete-file cmdfile)))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
You use this the same way.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;gnuplot&lt;/span&gt; &lt;span style="color: #008000;"&gt;"set title \"Simple Plots\" font \",20\"&lt;/span&gt;
&lt;span style="color: #008000;"&gt;set key left box&lt;/span&gt;
&lt;span style="color: #008000;"&gt;set samples 50&lt;/span&gt;
&lt;span style="color: #008000;"&gt;set style data points&lt;/span&gt;
&lt;span style="color: #008000;"&gt;set terminal png&lt;/span&gt;
&lt;span style="color: #008000;"&gt;set output \"gnuplot.png\"&lt;/span&gt;

&lt;span style="color: #008000;"&gt;plot [-10:10] sin(x),atan(x),cos(atan(x))"&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
&lt;img src="/media/gnuplot.png"&gt; 
&lt;/p&gt;

&lt;p&gt;
It has the same limitations as our string-based Python solution. The benefit of them is the native command structure for Python or gnuplot is used, so anything they can do you can too.
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-orgfe7800b" class="outline-2"&gt;
&lt;h2 id="orgfe7800b"&gt;&lt;span class="section-number-2"&gt;2&lt;/span&gt; An alternative approach using a DSL&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-2"&gt;
&lt;p&gt;
As an alternative, we consider here a domain specific language (DSL) that maps onto gnuplot. Suppose we could do this instead.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;gnuplot&lt;/span&gt;
 (set terminal png)
 (set output &lt;span style="color: #008000;"&gt;"test.png"&lt;/span&gt;)
 (set title &lt;span style="color: #008000;"&gt;"Simple Plots"&lt;/span&gt; font &lt;span style="color: #008000;"&gt;",20"&lt;/span&gt;)
 (set key left box)
 (set samples 50)
 (set style data points)

 (&lt;span style="color: #0000FF;"&gt;plot&lt;/span&gt; [-10:10] sin\(x\) \,atan\(x\) \,cos\(atan\(x\)\)))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Here is the figure from that code. The most annoying part of this is in the plot function we have to escape all the parentheses and commas, but otherwise it looks pretty lispy. The output of that program is the gnuplot commands that were generated for making the plot.
&lt;img src="/media/test.png"&gt; 
&lt;/p&gt;

&lt;p&gt;
This retains a lot of benefits of programming in lisp. &lt;code&gt;gnuplot&lt;/code&gt; has to be a macro though because we do not want to evaluate the s-expressions inside as lisp. For starters they just look lispy, I don't actually use them as lisp at all. Instead we transform them to the gnuplot code.
&lt;/p&gt;

&lt;p&gt;
In the following code, I will develop the gnuplot macro. It has some sticky and tricky points, and it is not obvious it will support all the features of gnuplot, but I learned a lot doing it that I will share here.
&lt;/p&gt;

&lt;p&gt;
Starting with a simple form inside the macro, I wanted to convert (set output "test.png") to "set output \"test.png\"". For this DSL, I want to treat every symbol in the form as if it should be turned into a string, anything that is a string should be quoted, and anything that is in parentheses (i.e. it passes listp) should be evaluated and converted to a string. Then all those strings should be joined by spaces. Here is a macro that does that (adapted from a solution at &lt;a href="https://emacs.stackexchange.com/questions/32558/eval-some-arguments-in-a-macro/32570?noredirect=1#comment50186_32570"&gt;https://emacs.stackexchange.com/questions/32558/eval-some-arguments-in-a-macro/32570?noredirect=1#comment50186_32570&lt;/a&gt;).
&lt;/p&gt;

&lt;p&gt;
There are a couple of corner cases that are handled here. If the arg is a string, we quote it.  If the arg is not a symbol or string, then it is evaluated and converted to a string. Importantly, this is done in the run environment though, so we can inject variables into the gnuplot code.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defmacro&lt;/span&gt; &lt;span style="color: #006699;"&gt;gargs&lt;/span&gt; (&lt;span style="color: #6434A3;"&gt;&amp;amp;rest&lt;/span&gt; args)
  &lt;span style="color: #036A07;"&gt;"Convert symbols to strings, quote strings, and (expr) to what they evaluate to."&lt;/span&gt;
  `(s-join &lt;span style="color: #008000;"&gt;" "&lt;/span&gt; (list ,@(cl-mapcan
                        (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (s)
                          (list
                           (&lt;span style="color: #0000FF;"&gt;cond&lt;/span&gt;
                            ((symbolp s)
                             (symbol-name s))
                            ((stringp s)
                             (format &lt;span style="color: #008000;"&gt;"\"%s\""&lt;/span&gt; s))
                            (t
                             `(&lt;span style="color: #0000FF;"&gt;with-output-to-string&lt;/span&gt;
                                (princ ,s))))))
                        args))))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Here are a few examples of how it works. The loop is just to get a vertical table in org-mode for the blog post.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;loop&lt;/span&gt; for s in
      (list (&lt;span style="color: #0000FF;"&gt;gargs&lt;/span&gt; set key title &lt;span style="color: #008000;"&gt;"before fit"&lt;/span&gt; size \, (+ 5 5))
            (&lt;span style="color: #0000FF;"&gt;gargs&lt;/span&gt; set title &lt;span style="color: #008000;"&gt;"red"&lt;/span&gt;)
            (&lt;span style="color: #0000FF;"&gt;gargs&lt;/span&gt; set yrange [0:*])
            (&lt;span style="color: #0000FF;"&gt;gargs&lt;/span&gt; &lt;span style="color: #008000;"&gt;"5"&lt;/span&gt;)
            (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((x 6)) (&lt;span style="color: #0000FF;"&gt;gargs&lt;/span&gt; (identity x)))
            (&lt;span style="color: #0000FF;"&gt;gargs&lt;/span&gt; 'x)
            (&lt;span style="color: #0000FF;"&gt;gargs&lt;/span&gt; '(x))
            (&lt;span style="color: #0000FF;"&gt;gargs&lt;/span&gt; set label 1 &lt;span style="color: #008000;"&gt;"plot for [n=2:10] sin(x*n)/n"&lt;/span&gt; at graph .95\, graph .92 right))
      collect
      (list s))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
A limitation of this is that we either have quote things like parentheses, commas, semi-colons and sometimes square brackets:
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;gargs&lt;/span&gt; plot for [n=2:10] sin\(x*n\)/n notitle lw \(13-n\)/2)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Or we have to use the string form instead; we can always fall back to that.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;gargs&lt;/span&gt; &lt;span style="color: #008000;"&gt;"plot for [n=2:10] sin(x*n)/n notitle lw (13-n)/2"&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
The macro above will do the grunt work on each form in the gnuplot macro. Finally, for the gnuplot macro, I want to take all the forms, convert them to gnuplot commands, write them to a temporary file, and then run gnuplot on the file, and finally delete the temp file. I assume we start with a gui terminal so graphs pop up unless you change it in your macro body. Here is that macro. It returns the generated code so it easy to see if you got the right program.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defmacro&lt;/span&gt; &lt;span style="color: #006699;"&gt;gnuplot&lt;/span&gt; (&lt;span style="color: #6434A3;"&gt;&amp;amp;rest&lt;/span&gt; forms)
  (&lt;span style="color: #0000FF;"&gt;let*&lt;/span&gt; ((temporary-file-directory &lt;span style="color: #008000;"&gt;"."&lt;/span&gt;)
         (cmdfile (make-temp-file &lt;span style="color: #008000;"&gt;"gnuplot-cmds-"&lt;/span&gt; nil &lt;span style="color: #008000;"&gt;".gpl"&lt;/span&gt;))
         (shellcmd (format &lt;span style="color: #008000;"&gt;"gnuplot --persist -c \"%s\""&lt;/span&gt; cmdfile))
         (cmd-string))
    `(&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((cmd-string (s-join &lt;span style="color: #008000;"&gt;"\n"&lt;/span&gt; (list ,@(mapcar (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (x)
                                                      (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (stringp x)
                                                          x
                                                        `(&lt;span style="color: #0000FF;"&gt;gargs&lt;/span&gt; ,@x)))
                                                    forms)))))
       (&lt;span style="color: #0000FF;"&gt;with-temp-file&lt;/span&gt; ,cmdfile
         (insert &lt;span style="color: #008000;"&gt;"set terminal qt\n"&lt;/span&gt;)
         (insert cmd-string)
         (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; cmd-string (buffer-string)))
       (shell-command ,shellcmd)
       (delete-file ,cmdfile)
       cmd-string)))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Here is a figure adapted from &lt;a href="http://gnuplot.sourceforge.net/demo/iterate.html"&gt;http://gnuplot.sourceforge.net/demo/iterate.html&lt;/a&gt;. I use the string form for the last line to avoid escaping all the special characters.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;gnuplot&lt;/span&gt;
 (set terminal png)
 (set output &lt;span style="color: #008000;"&gt;"iteration.png"&lt;/span&gt;)
 (set title &lt;span style="color: #008000;"&gt;"Iteration within plot command"&lt;/span&gt;)
 (set xrange [0:3])
 (set label 1 &lt;span style="color: #008000;"&gt;"plot for [n=2:10] sin(x*n)/n"&lt;/span&gt; at graph .95\, graph .92 right)
 &lt;span style="color: #008000;"&gt;"plot for [n=2:10] sin(x*n)/n notitle lw (13-n)/2"&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Here is the resulting figure.
&lt;/p&gt;

&lt;p&gt;
&lt;img src="/media/iteration.png"&gt; 
&lt;/p&gt;

&lt;p&gt;
That is overall pretty sweet. There is a little dissonance between the strings, escaped comma, etc.., and it is not terribly ideal for integrating with regular lisp code inside the macro yet. That seems to be a feature of my choice to use (expr) as the syntax to evaluate a form. It means you have to do some gymnastics to get some s-expressions into the graphs. For example below I use a couple of variables to inject values. To get a string I have to use format to add the extra quotes, and to get the number I have to use the identity function. I also used escaped characters in the last line to see the difference.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((ts &lt;span style="color: #008000;"&gt;"Iteration and substitution"&lt;/span&gt;)
      (x0 0)
      (xf 3)
      (g1 0.95)
      (g2 0.92))
  (&lt;span style="color: #0000FF;"&gt;gnuplot&lt;/span&gt;
   (set terminal png)
   (set output &lt;span style="color: #008000;"&gt;"iteration-2.png"&lt;/span&gt;)
   (set title (format &lt;span style="color: #008000;"&gt;"\"%s\""&lt;/span&gt; ts))
   &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;Note the escaped square brackets&lt;/span&gt;
   (set xrange \[ (identity x0) : (identity xf) \])
   (set label 1 &lt;span style="color: #008000;"&gt;"plot for [n=2:10] sin(x*n)/n"&lt;/span&gt; at graph (identity g1) \, graph (identity g2) right)
   &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;note here I escaped the parentheses!&lt;/span&gt;
   (&lt;span style="color: #0000FF;"&gt;plot&lt;/span&gt; for [n=2:10] sin\(x*n\)/n notitle lw \(13-n\)/2)))
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;
&lt;img src="/media/iteration-2.png"&gt; 
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;



&lt;div id="outline-container-orga773a9d" class="outline-2"&gt;
&lt;h2 id="orga773a9d"&gt;&lt;span class="section-number-2"&gt;3&lt;/span&gt; Summary&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-3"&gt;
&lt;p&gt;
For the simple plots here, my DSL worked ok. There is a tradeoff in the syntax I chose that has some consequences. We cannot use the values of symbols in this DSL without resorting to hackery like (identity sym). We also cannot use the infix notation for sin(x) without quoting it as "sin(x)" or escaping the parentheses, e.g. &lt;code&gt;sin\(x\)&lt;/code&gt;, likewise square brackets which lisp will read  as a vector. Commas have to be escaped, which is probably an emacs-lisp issue. To address that would require a reader macro which emacs-lisp does not have great support for. I am calling this experiment done for now. I have another syntax idea to try out another day.
&lt;/p&gt;

&lt;p&gt;
Here is a preview of what it might look like. It is basically the same but I reuse keywords to indicate that :x0 should be replaced by whatever x0 evaluates to, and (: - 1 0.05) should be evaluated. The special character escaping is still there of course, since that is a limitation of the emacs lisp reader I think. I might try using x0? and (? - 1 0.05) instead. That might be less confusing. I like that the keywords are syntax highlighted for free though, and you can't use them for anything else.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((ts &lt;span style="color: #008000;"&gt;"Iteration and substitution"&lt;/span&gt;)
      (x0 0)
      (xf 3)
      (g2 0.92))
  (&lt;span style="color: #0000FF;"&gt;gnuplot&lt;/span&gt;
   (set terminal png)
   (set output &lt;span style="color: #008000;"&gt;"iteration-2.png"&lt;/span&gt;)
   (set title &lt;span style="color: #006FE0;"&gt;:ts&lt;/span&gt;)
   &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;Note the escaped square brackets&lt;/span&gt;
   (set xrange \[ &lt;span style="color: #006FE0;"&gt;:x0&lt;/span&gt; : &lt;span style="color: #006FE0;"&gt;:xf&lt;/span&gt; \])
   (set label 1 &lt;span style="color: #008000;"&gt;"plot for [n=2:10] sin(x*n)/n"&lt;/span&gt; at graph (&lt;span style="color: #0000FF;"&gt;:&lt;/span&gt; - 1 0.05) \, graph &lt;span style="color: #006FE0;"&gt;:g2&lt;/span&gt; right)
   &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;note here I escaped the parentheses!&lt;/span&gt;
   (&lt;span style="color: #0000FF;"&gt;plot&lt;/span&gt; for [n=2:10] sin(x*n)/n notitle lw (13-n)/2)))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
This has the benefit of a little cleaner injection of variables and selective execution of parenthetical expressions, we will just ignore any that don't pass (= (car expr) :). That May not work for sin((: + 1 1) x) though, unless I escape the outer parentheses too.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2017 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;
&lt;p&gt;&lt;a href="/org/2017/05/04/An-emacs-lisp-dsl-for-gnuplot.org"&gt;org-mode source&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Org-mode version = 9.0.5&lt;/p&gt;]]></content:encoded>
    </item>
    <item>
      <title>Calling remote code-blocks in org-mode</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2016/02/09/Calling-remote-code-blocks-in-org-mode</link>
      <pubDate>Tue, 09 Feb 2016 20:40:59 EST</pubDate>
      <category><![CDATA[orgmode]]></category>
      <category><![CDATA[interactive]]></category>
      <category><![CDATA[plotting]]></category>
      <guid isPermaLink="false">-ajoa6PEQC22p9Dndgz702zHuJo=</guid>
      <description>Calling remote code-blocks in org-mode</description>
      <content:encoded><![CDATA[


&lt;div id="table-of-contents"&gt;
&lt;h2&gt;Table of Contents&lt;/h2&gt;
&lt;div id="text-table-of-contents"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#sec-1"&gt;1. References&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;
We often write code in supporting information files that generates figures or tables in a scientific manuscript. Today, we explore how to call those code blocks remotely but get the output in the file we call it from. We will write code in &lt;a href="/media/2016-02-09-Calling-remote-code-blocks-in-org-mode/si.org"&gt;si.org&lt;/a&gt; that generates an interactive figure that is presented in this file. We will use data published in &lt;a class='org-ref-reference' href="#hallenbeck-2015-compar-co2"&gt;hallenbeck-2015-compar-co2&lt;/a&gt;. You can find the data we used in the SI for that paper, or more conveniently &lt;a href="https://github.com/KitchinHUB/kitchingroup-62"&gt;here&lt;/a&gt; .
&lt;/p&gt;

&lt;p&gt;
So, we make a named code block in the &lt;a href="/media/2016-02-09-Calling-remote-code-blocks-in-org-mode/si.org"&gt;si.org&lt;/a&gt; file called "figure-1". Then we call it like this:
&lt;/p&gt;

&lt;pre class="example"&gt;
#+call: si.org:figure-1() :wrap html
&lt;/pre&gt;

&lt;p&gt;
That executes the code block in the other file, and wraps the output in an HTML block &lt;i&gt;in this file&lt;/i&gt;! I do not like my code blocks to execute when I export because they are usually expensive calculations, so I have to manually run the line with C-c C-c, but you can override that behavior with a local setting of org-export-babel-evaluate. So, without further delay, here is the result. Now we have a nice, neat blog post file, with code in an &lt;a href="/media/2016-02-09-Calling-remote-code-blocks-in-org-mode/si.org"&gt;si.org&lt;/a&gt; file!
&lt;/p&gt;

&lt;iframe id="igraph" scrolling="no" style="border:none;"seamless="seamless" src="https://plot.ly/~jkitchin/6.embed" height="525" width="100%"&gt;&lt;/iframe&gt;

&lt;div id="outline-container-sec-1" class="outline-2"&gt;
&lt;h2 id="sec-1"&gt;&lt;span class="section-number-2"&gt;1&lt;/span&gt; References&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;
&lt;p&gt;
&lt;h1 class='org-ref-bib-h1'&gt;Bibliography&lt;/h1&gt;
&lt;ul class='org-ref-bib'&gt;&lt;li&gt;&lt;a id="hallenbeck-2015-compar-co2"&gt;[hallenbeck-2015-compar-co2] "Alexander Hallenbeck, Adefemi Egbebi, Kevin Resnik, , David Hopkinson, Shelley Anna &amp; John Kitchin", Comparative Microfluidic Screening of Amino Acid Salt  Solutions for Post-Combustion \ceCO2 Capture, &lt;i&gt;"International Journal of Greenhouse Gas Control "&lt;/i&gt;, &lt;b&gt;43&lt;/b&gt;, 189 - 197 (2015). &lt;a href="http://www.sciencedirect.com/science/article/pii/S1750583615301134"&gt;link&lt;/a&gt;. &lt;a href="https://doi.org/10.1016/j.ijggc.2015.10.026"&gt;doi&lt;/a&gt;.&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2016 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2016/02/09/Calling-remote-code-blocks-in-org-mode.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;&lt;p&gt;Org-mode version = 8.2.10&lt;/p&gt;
]]></content:encoded>
    </item>
    <item>
      <title>Interactive figures in blog posts with mpld3</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2016/02/08/Interactive-figures-in-blog-posts-with-mpld3</link>
      <pubDate>Mon, 08 Feb 2016 07:33:23 EST</pubDate>
      <category><![CDATA[plotting]]></category>
      <category><![CDATA[interactive]]></category>
      <category><![CDATA[python]]></category>
      <guid isPermaLink="false">1CrAIWaPYEtSGBHf15JTbQbHCHI=</guid>
      <description>Interactive figures in blog posts with mpld3</description>
      <content:encoded><![CDATA[



&lt;p&gt;
Continuing the exploration of interactive figures, today we consider the Python plotting library &lt;a href="http://mpld3.github.io/index.html"&gt;mpld3&lt;/a&gt; . We will again use our own published data. We wrote this great paper on core level shifts (CLS) in Cu-Pd alloys &lt;a class='org-ref-reference' href="#boes-2015-core-cu"&gt;boes-2015-core-cu&lt;/a&gt;. I want an interactive figure that shows the name of the calculation on each point as a tooltip. This data is all stored in the supporting information file, and you can see how we use it &lt;a href="#sec-1"&gt;here&lt;/a&gt;. This figure shows how the core level shift of a Cu atom changes depending on the number of nearest neighbor Cu atoms. Just hover your mouse over a point to see the name and CLS for that point.
&lt;/p&gt;



&lt;style&gt;

&lt;/style&gt;

&lt;div id="fig_el8116045214667689201799167"&gt;&lt;/div&gt;
&lt;script&gt;
function mpld3_load_lib(url, callback){
  var s = document.createElement('script');
  s.src = url;
  s.async = true;
  s.onreadystatechange = s.onload = callback;
  s.onerror = function(){console.warn("failed to load library " + url);};
  document.getElementsByTagName("head")[0].appendChild(s);
}

if(typeof(mpld3) !== "undefined" &amp;&amp; mpld3._mpld3IsLoaded){
   // already loaded: just create the figure
   !function(mpld3){

    mpld3.register_plugin("htmltooltip", HtmlTooltipPlugin);
    HtmlTooltipPlugin.prototype = Object.create(mpld3.Plugin.prototype);
    HtmlTooltipPlugin.prototype.constructor = HtmlTooltipPlugin;
    HtmlTooltipPlugin.prototype.requiredProps = ["id"];
    HtmlTooltipPlugin.prototype.defaultProps = {labels:null, hoffset:0, voffset:10};
    function HtmlTooltipPlugin(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };

    HtmlTooltipPlugin.prototype.draw = function(){
       var obj = mpld3.get_element(this.props.id);
       var labels = this.props.labels;
       var tooltip = d3.select("body").append("div")
                    .attr("class", "mpld3-tooltip")
                    .style("position", "absolute")
                    .style("z-index", "10")
                    .style("visibility", "hidden");

       obj.elements()
           .on("mouseover", function(d, i){
                              tooltip.html(labels[i])
                                     .style("visibility", "visible");})
           .on("mousemove", function(d, i){
                    tooltip
                      .style("top", d3.event.pageY + this.props.voffset + "px")
                      .style("left",d3.event.pageX + this.props.hoffset + "px");
                 }.bind(this))
           .on("mouseout",  function(d, i){
                           tooltip.style("visibility", "hidden");});
    };

       mpld3.draw_figure("fig_el8116045214667689201799167", {"axes": [{"xlim": [-0.10000000000000001, 5.0999999999999996], "yscale": "linear", "axesbg": "#FFFFFF", "texts": [{"v_baseline": "hanging", "h_anchor": "middle", "color": "#000000", "text": "# Cu Nearest neighbors", "coordinates": "axes", "zorder": 3, "alpha": 1, "fontsize": 12.0, "position": [0.5, -0.059895833333333329], "rotation": -0.0, "id": "el811604301509136"}, {"v_baseline": "auto", "h_anchor": "middle", "color": "#000000", "text": "Cu 2p(3/2) Core Level Shift (eV)", "coordinates": "axes", "zorder": 3, "alpha": 1, "fontsize": 12.0, "position": [-0.081149193548387094, 0.5], "rotation": -90.0, "id": "el811604590615056"}, {"v_baseline": "auto", "h_anchor": "middle", "color": "#000000", "text": "Hover over a point to see the calculation name", "coordinates": "axes", "zorder": 3, "alpha": 1, "fontsize": 14.399999999999999, "position": [0.5, 1.0144675925925926], "rotation": -0.0, "id": "el811604590601360"}], "zoomable": true, "images": [], "xdomain": [-0.10000000000000001, 5.0999999999999996], "ylim": [-1.1499999999999999, -0.59999999999999998], "paths": [], "sharey": [], "sharex": [], "axesbgalpha": null, "axes": [{"scale": "linear", "tickformat": null, "grid": {"gridOn": false}, "fontsize": 12.0, "position": "bottom", "nticks": 8, "tickvalues": null}, {"scale": "linear", "tickformat": null, "grid": {"gridOn": false}, "fontsize": 12.0, "position": "left", "nticks": 8, "tickvalues": null}], "lines": [], "markers": [], "id": "el811604578565392", "ydomain": [-1.1499999999999999, -0.59999999999999998], "collections": [{"paths": [[[[0.0, -0.5], [0.13260155, -0.5], [0.25978993539242673, -0.44731684579412084], [0.3535533905932738, -0.3535533905932738], [0.44731684579412084, -0.25978993539242673], [0.5, -0.13260155], [0.5, 0.0], [0.5, 0.13260155], [0.44731684579412084, 0.25978993539242673], [0.3535533905932738, 0.3535533905932738], [0.25978993539242673, 0.44731684579412084], [0.13260155, 0.5], [0.0, 0.5], [-0.13260155, 0.5], [-0.25978993539242673, 0.44731684579412084], [-0.3535533905932738, 0.3535533905932738], [-0.44731684579412084, 0.25978993539242673], [-0.5, 0.13260155], [-0.5, 0.0], [-0.5, -0.13260155], [-0.44731684579412084, -0.25978993539242673], [-0.3535533905932738, -0.3535533905932738], [-0.25978993539242673, -0.44731684579412084], [-0.13260155, -0.5], [0.0, -0.5]], ["M", "C", "C", "C", "C", "C", "C", "C", "C", "Z"]]], "edgecolors": ["#000000"], "edgewidths": [1.0], "offsets": "data01", "yindex": 1, "id": "el811604578805904", "pathtransforms": [[5.555555555555555, 0.0, 0.0, 5.555555555555555, 0.0, 0.0]], "pathcoordinates": "display", "offsetcoordinates": "data", "zorder": 1, "xindex": 0, "alphas": [null], "facecolors": ["#007F00"]}], "xscale": "linear", "bbox": [0.125, 0.099999999999999978, 0.77500000000000002, 0.80000000000000004]}], "height": 480.0, "width": 640.0, "plugins": [{"type": "reset"}, {"enabled": false, "button": true, "type": "zoom"}, {"enabled": false, "button": true, "type": "boxzoom"}, {"voffset": 0, "labels": ["I2C0 (2, -0.935278)", "I2C1 (2, -0.946807)", "I2C2 (2, -0.943939)", "I3C0 (3, -0.833261)", "I3C1 (3, -0.843403)", "I3C2 (3, -0.855672)", "I4C0 (4, -0.724523)", "I4C1 (4, -0.747264)", "I4C2 (4, -0.747883)", "I4C3 (4, -0.735007)", "I4C4 (4, -0.736147)", "I5C0 (5, -0.632788)", "I5C1 (5, -0.646229)", "I5C2 (5, -0.654132)", "(1, -1.041875)", "(0, -1.127344)"], "type": "htmltooltip", "id": "el811604578805904", "hoffset": 10}], "data": {"data01": [[2.0, -0.9352779999999825], [2.0, -0.9468069999999216], [2.0, -0.9439389999999435], [3.0, -0.8332609999999363], [3.0, -0.8434029999999382], [3.0, -0.85567199999997], [4.0, -0.7245230000000049], [4.0, -0.747263999999916], [4.0, -0.7478829999999164], [4.0, -0.7350069999999391], [4.0, -0.7361470000000168], [5.0, -0.6327879999999766], [5.0, -0.6462289999999484], [5.0, -0.6541319999999757], [1.0, -1.0418749999999761], [0.0, -1.1273439999999653]]}, "id": "el811604521466768"});
   }(mpld3);
}else if(typeof define === "function" &amp;&amp; define.amd){
   // require.js is available: use it to load d3/mpld3
   require.config({paths: {d3: "https://mpld3.github.io/js/d3.v3.min"}});
   require(["d3"], function(d3){
      window.d3 = d3;
      mpld3_load_lib("https://mpld3.github.io/js/mpld3.v0.2.js", function(){

    mpld3.register_plugin("htmltooltip", HtmlTooltipPlugin);
    HtmlTooltipPlugin.prototype = Object.create(mpld3.Plugin.prototype);
    HtmlTooltipPlugin.prototype.constructor = HtmlTooltipPlugin;
    HtmlTooltipPlugin.prototype.requiredProps = ["id"];
    HtmlTooltipPlugin.prototype.defaultProps = {labels:null, hoffset:0, voffset:10};
    function HtmlTooltipPlugin(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };

    HtmlTooltipPlugin.prototype.draw = function(){
       var obj = mpld3.get_element(this.props.id);
       var labels = this.props.labels;
       var tooltip = d3.select("body").append("div")
                    .attr("class", "mpld3-tooltip")
                    .style("position", "absolute")
                    .style("z-index", "10")
                    .style("visibility", "hidden");

       obj.elements()
           .on("mouseover", function(d, i){
                              tooltip.html(labels[i])
                                     .style("visibility", "visible");})
           .on("mousemove", function(d, i){
                    tooltip
                      .style("top", d3.event.pageY + this.props.voffset + "px")
                      .style("left",d3.event.pageX + this.props.hoffset + "px");
                 }.bind(this))
           .on("mouseout",  function(d, i){
                           tooltip.style("visibility", "hidden");});
    };

         mpld3.draw_figure("fig_el8116045214667689201799167", {"axes": [{"xlim": [-0.10000000000000001, 5.0999999999999996], "yscale": "linear", "axesbg": "#FFFFFF", "texts": [{"v_baseline": "hanging", "h_anchor": "middle", "color": "#000000", "text": "# Cu Nearest neighbors", "coordinates": "axes", "zorder": 3, "alpha": 1, "fontsize": 12.0, "position": [0.5, -0.059895833333333329], "rotation": -0.0, "id": "el811604301509136"}, {"v_baseline": "auto", "h_anchor": "middle", "color": "#000000", "text": "Cu 2p(3/2) Core Level Shift (eV)", "coordinates": "axes", "zorder": 3, "alpha": 1, "fontsize": 12.0, "position": [-0.081149193548387094, 0.5], "rotation": -90.0, "id": "el811604590615056"}, {"v_baseline": "auto", "h_anchor": "middle", "color": "#000000", "text": "Hover over a point to see the calculation name", "coordinates": "axes", "zorder": 3, "alpha": 1, "fontsize": 14.399999999999999, "position": [0.5, 1.0144675925925926], "rotation": -0.0, "id": "el811604590601360"}], "zoomable": true, "images": [], "xdomain": [-0.10000000000000001, 5.0999999999999996], "ylim": [-1.1499999999999999, -0.59999999999999998], "paths": [], "sharey": [], "sharex": [], "axesbgalpha": null, "axes": [{"scale": "linear", "tickformat": null, "grid": {"gridOn": false}, "fontsize": 12.0, "position": "bottom", "nticks": 8, "tickvalues": null}, {"scale": "linear", "tickformat": null, "grid": {"gridOn": false}, "fontsize": 12.0, "position": "left", "nticks": 8, "tickvalues": null}], "lines": [], "markers": [], "id": "el811604578565392", "ydomain": [-1.1499999999999999, -0.59999999999999998], "collections": [{"paths": [[[[0.0, -0.5], [0.13260155, -0.5], [0.25978993539242673, -0.44731684579412084], [0.3535533905932738, -0.3535533905932738], [0.44731684579412084, -0.25978993539242673], [0.5, -0.13260155], [0.5, 0.0], [0.5, 0.13260155], [0.44731684579412084, 0.25978993539242673], [0.3535533905932738, 0.3535533905932738], [0.25978993539242673, 0.44731684579412084], [0.13260155, 0.5], [0.0, 0.5], [-0.13260155, 0.5], [-0.25978993539242673, 0.44731684579412084], [-0.3535533905932738, 0.3535533905932738], [-0.44731684579412084, 0.25978993539242673], [-0.5, 0.13260155], [-0.5, 0.0], [-0.5, -0.13260155], [-0.44731684579412084, -0.25978993539242673], [-0.3535533905932738, -0.3535533905932738], [-0.25978993539242673, -0.44731684579412084], [-0.13260155, -0.5], [0.0, -0.5]], ["M", "C", "C", "C", "C", "C", "C", "C", "C", "Z"]]], "edgecolors": ["#000000"], "edgewidths": [1.0], "offsets": "data01", "yindex": 1, "id": "el811604578805904", "pathtransforms": [[5.555555555555555, 0.0, 0.0, 5.555555555555555, 0.0, 0.0]], "pathcoordinates": "display", "offsetcoordinates": "data", "zorder": 1, "xindex": 0, "alphas": [null], "facecolors": ["#007F00"]}], "xscale": "linear", "bbox": [0.125, 0.099999999999999978, 0.77500000000000002, 0.80000000000000004]}], "height": 480.0, "width": 640.0, "plugins": [{"type": "reset"}, {"enabled": false, "button": true, "type": "zoom"}, {"enabled": false, "button": true, "type": "boxzoom"}, {"voffset": 0, "labels": ["I2C0 (2, -0.935278)", "I2C1 (2, -0.946807)", "I2C2 (2, -0.943939)", "I3C0 (3, -0.833261)", "I3C1 (3, -0.843403)", "I3C2 (3, -0.855672)", "I4C0 (4, -0.724523)", "I4C1 (4, -0.747264)", "I4C2 (4, -0.747883)", "I4C3 (4, -0.735007)", "I4C4 (4, -0.736147)", "I5C0 (5, -0.632788)", "I5C1 (5, -0.646229)", "I5C2 (5, -0.654132)", "(1, -1.041875)", "(0, -1.127344)"], "type": "htmltooltip", "id": "el811604578805904", "hoffset": 10}], "data": {"data01": [[2.0, -0.9352779999999825], [2.0, -0.9468069999999216], [2.0, -0.9439389999999435], [3.0, -0.8332609999999363], [3.0, -0.8434029999999382], [3.0, -0.85567199999997], [4.0, -0.7245230000000049], [4.0, -0.747263999999916], [4.0, -0.7478829999999164], [4.0, -0.7350069999999391], [4.0, -0.7361470000000168], [5.0, -0.6327879999999766], [5.0, -0.6462289999999484], [5.0, -0.6541319999999757], [1.0, -1.0418749999999761], [0.0, -1.1273439999999653]]}, "id": "el811604521466768"});
      });
    });
}else{
    // require.js not available: dynamically load d3 &amp; mpld3
    mpld3_load_lib("https://mpld3.github.io/js/d3.v3.min.js", function(){
         mpld3_load_lib("https://mpld3.github.io/js/mpld3.v0.2.js", function(){

    mpld3.register_plugin("htmltooltip", HtmlTooltipPlugin);
    HtmlTooltipPlugin.prototype = Object.create(mpld3.Plugin.prototype);
    HtmlTooltipPlugin.prototype.constructor = HtmlTooltipPlugin;
    HtmlTooltipPlugin.prototype.requiredProps = ["id"];
    HtmlTooltipPlugin.prototype.defaultProps = {labels:null, hoffset:0, voffset:10};
    function HtmlTooltipPlugin(fig, props){
        mpld3.Plugin.call(this, fig, props);
    };

    HtmlTooltipPlugin.prototype.draw = function(){
       var obj = mpld3.get_element(this.props.id);
       var labels = this.props.labels;
       var tooltip = d3.select("body").append("div")
                    .attr("class", "mpld3-tooltip")
                    .style("position", "absolute")
                    .style("z-index", "10")
                    .style("visibility", "hidden");

       obj.elements()
           .on("mouseover", function(d, i){
                              tooltip.html(labels[i])
                                     .style("visibility", "visible");})
           .on("mousemove", function(d, i){
                    tooltip
                      .style("top", d3.event.pageY + this.props.voffset + "px")
                      .style("left",d3.event.pageX + this.props.hoffset + "px");
                 }.bind(this))
           .on("mouseout",  function(d, i){
                           tooltip.style("visibility", "hidden");});
    };

                 mpld3.draw_figure("fig_el8116045214667689201799167", {"axes": [{"xlim": [-0.10000000000000001, 5.0999999999999996], "yscale": "linear", "axesbg": "#FFFFFF", "texts": [{"v_baseline": "hanging", "h_anchor": "middle", "color": "#000000", "text": "# Cu Nearest neighbors", "coordinates": "axes", "zorder": 3, "alpha": 1, "fontsize": 12.0, "position": [0.5, -0.059895833333333329], "rotation": -0.0, "id": "el811604301509136"}, {"v_baseline": "auto", "h_anchor": "middle", "color": "#000000", "text": "Cu 2p(3/2) Core Level Shift (eV)", "coordinates": "axes", "zorder": 3, "alpha": 1, "fontsize": 12.0, "position": [-0.081149193548387094, 0.5], "rotation": -90.0, "id": "el811604590615056"}, {"v_baseline": "auto", "h_anchor": "middle", "color": "#000000", "text": "Hover over a point to see the calculation name", "coordinates": "axes", "zorder": 3, "alpha": 1, "fontsize": 14.399999999999999, "position": [0.5, 1.0144675925925926], "rotation": -0.0, "id": "el811604590601360"}], "zoomable": true, "images": [], "xdomain": [-0.10000000000000001, 5.0999999999999996], "ylim": [-1.1499999999999999, -0.59999999999999998], "paths": [], "sharey": [], "sharex": [], "axesbgalpha": null, "axes": [{"scale": "linear", "tickformat": null, "grid": {"gridOn": false}, "fontsize": 12.0, "position": "bottom", "nticks": 8, "tickvalues": null}, {"scale": "linear", "tickformat": null, "grid": {"gridOn": false}, "fontsize": 12.0, "position": "left", "nticks": 8, "tickvalues": null}], "lines": [], "markers": [], "id": "el811604578565392", "ydomain": [-1.1499999999999999, -0.59999999999999998], "collections": [{"paths": [[[[0.0, -0.5], [0.13260155, -0.5], [0.25978993539242673, -0.44731684579412084], [0.3535533905932738, -0.3535533905932738], [0.44731684579412084, -0.25978993539242673], [0.5, -0.13260155], [0.5, 0.0], [0.5, 0.13260155], [0.44731684579412084, 0.25978993539242673], [0.3535533905932738, 0.3535533905932738], [0.25978993539242673, 0.44731684579412084], [0.13260155, 0.5], [0.0, 0.5], [-0.13260155, 0.5], [-0.25978993539242673, 0.44731684579412084], [-0.3535533905932738, 0.3535533905932738], [-0.44731684579412084, 0.25978993539242673], [-0.5, 0.13260155], [-0.5, 0.0], [-0.5, -0.13260155], [-0.44731684579412084, -0.25978993539242673], [-0.3535533905932738, -0.3535533905932738], [-0.25978993539242673, -0.44731684579412084], [-0.13260155, -0.5], [0.0, -0.5]], ["M", "C", "C", "C", "C", "C", "C", "C", "C", "Z"]]], "edgecolors": ["#000000"], "edgewidths": [1.0], "offsets": "data01", "yindex": 1, "id": "el811604578805904", "pathtransforms": [[5.555555555555555, 0.0, 0.0, 5.555555555555555, 0.0, 0.0]], "pathcoordinates": "display", "offsetcoordinates": "data", "zorder": 1, "xindex": 0, "alphas": [null], "facecolors": ["#007F00"]}], "xscale": "linear", "bbox": [0.125, 0.099999999999999978, 0.77500000000000002, 0.80000000000000004]}], "height": 480.0, "width": 640.0, "plugins": [{"type": "reset"}, {"enabled": false, "button": true, "type": "zoom"}, {"enabled": false, "button": true, "type": "boxzoom"}, {"voffset": 0, "labels": ["I2C0 (2, -0.935278)", "I2C1 (2, -0.946807)", "I2C2 (2, -0.943939)", "I3C0 (3, -0.833261)", "I3C1 (3, -0.843403)", "I3C2 (3, -0.855672)", "I4C0 (4, -0.724523)", "I4C1 (4, -0.747264)", "I4C2 (4, -0.747883)", "I4C3 (4, -0.735007)", "I4C4 (4, -0.736147)", "I5C0 (5, -0.632788)", "I5C1 (5, -0.646229)", "I5C2 (5, -0.654132)", "(1, -1.041875)", "(0, -1.127344)"], "type": "htmltooltip", "id": "el811604578805904", "hoffset": 10}], "data": {"data01": [[2.0, -0.9352779999999825], [2.0, -0.9468069999999216], [2.0, -0.9439389999999435], [3.0, -0.8332609999999363], [3.0, -0.8434029999999382], [3.0, -0.85567199999997], [4.0, -0.7245230000000049], [4.0, -0.747263999999916], [4.0, -0.7478829999999164], [4.0, -0.7350069999999391], [4.0, -0.7361470000000168], [5.0, -0.6327879999999766], [5.0, -0.6462289999999484], [5.0, -0.6541319999999757], [1.0, -1.0418749999999761], [0.0, -1.1273439999999653]]}, "id": "el811604521466768"});
            })
         });
}
&lt;/script&gt;

&lt;div id="outline-container-sec-1" class="outline-2"&gt;
&lt;h2 id="sec-1"&gt;&lt;a id="ID-17D73543-F528-459D-95EF-B3AB3C4EEDC7" name="ID-17D73543-F528-459D-95EF-B3AB3C4EEDC7"&gt;&lt;/a&gt;&lt;span class="section-number-2"&gt;1&lt;/span&gt; Data and code&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;
&lt;p&gt;
You can check out our preprint at &lt;a href="https://github.com/KitchinHUB/kitchingroup-51"&gt;https://github.com/KitchinHUB/kitchingroup-51&lt;/a&gt; .  We are going to adapt the code to make Figure 6a in the manuscript interactive. The code needed a somewhat surprising amount of adaptation. Apparently the ase database interface has changed a lot since we write that paper, so the code here looks a bit different than what we published. The biggest difference is due to name-mangling so each key that started with a number now starts with _, and and periods are replaced by _ also. The rest of the script is nearly unchanged. At the end is the very small bit of mpld3 code that generates the figure for html. We will add tooltips onto datapoints to indicate what the name associated with each data point is. Here is the code.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python" id="mpld3-figure"&gt;&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; plt
&lt;span style="color: #0000FF;"&gt;from&lt;/span&gt; ase.db &lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; connect

&lt;span style="color: #8D8D84;"&gt;# &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;loads the ASE database and select certain keywords&lt;/span&gt;
&lt;span style="color: #BA36A5;"&gt;db&lt;/span&gt; = connect(&lt;span style="color: #008000;"&gt;'~/Desktop/cappa/kitchingroup-51/supporting-information/data.json'&lt;/span&gt;)

&lt;span style="color: #BA36A5;"&gt;keys&lt;/span&gt; = [&lt;span style="color: #008000;"&gt;'bcc'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'GS'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_54atom'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'ensam'&lt;/span&gt;]

&lt;span style="color: #BA36A5;"&gt;CLS&lt;/span&gt;, &lt;span style="color: #BA36A5;"&gt;IMP&lt;/span&gt;, &lt;span style="color: #BA36A5;"&gt;labels&lt;/span&gt; = [], [], []
&lt;span style="color: #0000FF;"&gt;for&lt;/span&gt; k &lt;span style="color: #0000FF;"&gt;in&lt;/span&gt; db.select(keys + [&lt;span style="color: #008000;"&gt;'_1cl'&lt;/span&gt;]):
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;name&lt;/span&gt; = k.keywords[-2]

&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;Cu0&lt;/span&gt; = db.select(&lt;span style="color: #008000;"&gt;'bcc,GS,_72atom,_0cl,_1_00Cu'&lt;/span&gt;).&lt;span style="color: #006FE0;"&gt;next&lt;/span&gt;().energy
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;Cu1&lt;/span&gt; = db.select(&lt;span style="color: #008000;"&gt;'bcc,GS,_72atom,_1cl,_1_00Cu'&lt;/span&gt;).&lt;span style="color: #006FE0;"&gt;next&lt;/span&gt;().energy
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;x0&lt;/span&gt; = db.select(&lt;span style="color: #008000;"&gt;','&lt;/span&gt;.join(keys + [name, &lt;span style="color: #008000;"&gt;'_0cl'&lt;/span&gt;])).&lt;span style="color: #006FE0;"&gt;next&lt;/span&gt;().energy
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;x1&lt;/span&gt; = k.energy

&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;cls0&lt;/span&gt; = x0 - Cu0
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;cls1&lt;/span&gt; = x1 - Cu1

&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   IMP.append(&lt;span style="color: #006FE0;"&gt;int&lt;/span&gt;(name[1]))
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   CLS.append(cls1 - cls0)
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;labels&lt;/span&gt; += [&lt;span style="color: #008000;"&gt;'{0} ({1}, {2})'&lt;/span&gt;.&lt;span style="color: #006FE0;"&gt;format&lt;/span&gt;(name, &lt;span style="color: #006FE0;"&gt;int&lt;/span&gt;(name[1]), cls1 - cls0)]

&lt;span style="color: #BA36A5;"&gt;Cu0&lt;/span&gt; = db.select(&lt;span style="color: #008000;"&gt;','&lt;/span&gt;.join([&lt;span style="color: #008000;"&gt;'bcc'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'GS'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_72atom'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; &lt;span style="color: #008000;"&gt;'_0cl'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_1_00Cu'&lt;/span&gt;])).&lt;span style="color: #006FE0;"&gt;next&lt;/span&gt;().energy
&lt;span style="color: #BA36A5;"&gt;Cu1&lt;/span&gt; = db.select(&lt;span style="color: #008000;"&gt;','&lt;/span&gt;.join([&lt;span style="color: #008000;"&gt;'bcc'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'GS'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_72atom'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; &lt;span style="color: #008000;"&gt;'_1cl'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_1_00Cu'&lt;/span&gt;])).&lt;span style="color: #006FE0;"&gt;next&lt;/span&gt;().energy

&lt;span style="color: #BA36A5;"&gt;x0&lt;/span&gt; = db.select(&lt;span style="color: #008000;"&gt;','&lt;/span&gt;.join([&lt;span style="color: #008000;"&gt;'bcc'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'GS'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_54atom'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;&lt;span style="color: #008000;"&gt;'_0cl'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_1'&lt;/span&gt;])).&lt;span style="color: #006FE0;"&gt;next&lt;/span&gt;().energy
&lt;span style="color: #BA36A5;"&gt;x1&lt;/span&gt; = db.select(&lt;span style="color: #008000;"&gt;','&lt;/span&gt;.join([&lt;span style="color: #008000;"&gt;'bcc'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'GS'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_54atom'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;&lt;span style="color: #008000;"&gt;'_1cl'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_1'&lt;/span&gt;])).&lt;span style="color: #006FE0;"&gt;next&lt;/span&gt;().energy

&lt;span style="color: #BA36A5;"&gt;cls0&lt;/span&gt; = x0 - Cu0
&lt;span style="color: #BA36A5;"&gt;cls1&lt;/span&gt; = x1 - Cu1

IMP.append(1)
CLS.append(cls1 - cls0)
&lt;span style="color: #BA36A5;"&gt;labels&lt;/span&gt; += [&lt;span style="color: #008000;"&gt;'(1, {0})'&lt;/span&gt;.&lt;span style="color: #006FE0;"&gt;format&lt;/span&gt;(cls1 - cls0)]

&lt;span style="color: #BA36A5;"&gt;Cu0&lt;/span&gt; = db.select(&lt;span style="color: #008000;"&gt;','&lt;/span&gt;.join([&lt;span style="color: #008000;"&gt;'bcc'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'GS'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_72atom'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; &lt;span style="color: #008000;"&gt;'_0cl'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_1_00Cu'&lt;/span&gt;])).&lt;span style="color: #006FE0;"&gt;next&lt;/span&gt;().energy
&lt;span style="color: #BA36A5;"&gt;Cu1&lt;/span&gt; = db.select(&lt;span style="color: #008000;"&gt;','&lt;/span&gt;.join([&lt;span style="color: #008000;"&gt;'bcc'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'GS'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_72atom'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; &lt;span style="color: #008000;"&gt;'_1cl'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_1_00Cu'&lt;/span&gt;])).&lt;span style="color: #006FE0;"&gt;next&lt;/span&gt;().energy

&lt;span style="color: #BA36A5;"&gt;x0&lt;/span&gt; = db.select(&lt;span style="color: #008000;"&gt;','&lt;/span&gt;.join([&lt;span style="color: #008000;"&gt;'bcc'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'GS'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_54atom'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;&lt;span style="color: #008000;"&gt;'_0cl'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_0'&lt;/span&gt;])).&lt;span style="color: #006FE0;"&gt;next&lt;/span&gt;().energy
&lt;span style="color: #BA36A5;"&gt;x1&lt;/span&gt; = db.select(&lt;span style="color: #008000;"&gt;','&lt;/span&gt;.join([&lt;span style="color: #008000;"&gt;'bcc'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'GS'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_54atom'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;&lt;span style="color: #008000;"&gt;'_1cl'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'_0'&lt;/span&gt;])).&lt;span style="color: #006FE0;"&gt;next&lt;/span&gt;().energy

&lt;span style="color: #BA36A5;"&gt;cls0&lt;/span&gt; = x0 - Cu0
&lt;span style="color: #BA36A5;"&gt;cls1&lt;/span&gt; = x1 - Cu1

IMP.append(0)
CLS.append(cls1 - cls0)
&lt;span style="color: #BA36A5;"&gt;labels&lt;/span&gt; += [&lt;span style="color: #008000;"&gt;'(0, {0})'&lt;/span&gt;.&lt;span style="color: #006FE0;"&gt;format&lt;/span&gt;(cls1 - cls0)]

&lt;span style="color: #BA36A5;"&gt;fig&lt;/span&gt; = plt.figure()

&lt;span style="color: #BA36A5;"&gt;p&lt;/span&gt; = plt.scatter(IMP, CLS, c=&lt;span style="color: #008000;"&gt;'g'&lt;/span&gt;, marker=&lt;span style="color: #008000;"&gt;'o'&lt;/span&gt;, s=25)
&lt;span style="color: #BA36A5;"&gt;ax1&lt;/span&gt; = plt.gca()
ax1.set_ylim(-1.15, -0.6)
ax1.set_xlim(-0.1, 5.1)

ax1.set_xlabel(&lt;span style="color: #008000;"&gt;'# Cu Nearest neighbors'&lt;/span&gt;)
ax1.set_ylabel(&lt;span style="color: #008000;"&gt;'Cu 2p(3/2) Core Level Shift (eV)'&lt;/span&gt;)

ax1.set_title(&lt;span style="color: #008000;"&gt;'Hover over a point to see the calculation name'&lt;/span&gt;)

&lt;span style="color: #8D8D84;"&gt;# &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;Now the mpld3 stuff.&lt;/span&gt;
&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; mpld3
&lt;span style="color: #0000FF;"&gt;from&lt;/span&gt; mpld3 &lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; plugins

&lt;span style="color: #BA36A5;"&gt;tooltip&lt;/span&gt; = plugins.PointHTMLTooltip(p, labels, voffset=0, hoffset=10)
plugins.connect(fig, tooltip)

&lt;span style="color: #0000FF;"&gt;print&lt;/span&gt; mpld3.fig_to_html(fig)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
I like this workflow pretty well. It seems less functional than plotly and Bokeh (e.g. it does not look like it you can export the data from the html here), but it is well integrated with Matplotlib, with my blogging style, and does not require a server, oran account. The code outputs html that is self-contained in the body of the html. The smooth integration with Matplotlib means I could have static images in org-mode, and dynamic images in HTML potentially. Overall, this is a nice tool for making interactive plots in blog posts.
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-sec-2" class="outline-2"&gt;
&lt;h2 id="sec-2"&gt;&lt;span class="section-number-2"&gt;2&lt;/span&gt; References&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-2"&gt;
&lt;p&gt;
&lt;h1 class='org-ref-bib-h1'&gt;Bibliography&lt;/h1&gt;
&lt;ul class='org-ref-bib'&gt;&lt;li&gt;&lt;a id="boes-2015-core-cu"&gt;[boes-2015-core-cu] Jacob Boes, Peter Kondratyuk, Chunrong Yin, James, Miller, Andrew Gellman &amp; John Kitchin, Core Level Shifts in Cu-Pd Alloys As a Function of Bulk  Composition and Structure, &lt;i&gt;Surface Science&lt;/i&gt;, &lt;b&gt;640&lt;/b&gt;, 127-132 (2015). &lt;a href="https://doi.org/10.1016/j.susc.2015.02.011"&gt;link&lt;/a&gt;. &lt;a href="https://doi.org/10.1016/j.susc.2015.02.011"&gt;doi&lt;/a&gt;.&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2016 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2016/02/08/Interactive-figures-in-blog-posts-with-mpld3.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;&lt;p&gt;Org-mode version = 8.2.10&lt;/p&gt;
]]></content:encoded>
    </item>
    <item>
      <title>Interactive Bokeh plots in HTML</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2016/02/07/Interactive-Bokeh-plots-in-HTML</link>
      <pubDate>Sun, 07 Feb 2016 10:53:45 EST</pubDate>
      <category><![CDATA[plotting]]></category>
      <category><![CDATA[interactive]]></category>
      <category><![CDATA[python]]></category>
      <guid isPermaLink="false">CM9ctWbQgZjxBLQKmokTp2qMm6Y=</guid>
      <description>Interactive Bokeh plots in HTML</description>
      <content:encoded><![CDATA[


&lt;div id="table-of-contents"&gt;
&lt;h2&gt;Table of Contents&lt;/h2&gt;
&lt;div id="text-table-of-contents"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#sec-1"&gt;1. The data and code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#sec-2"&gt;2. References&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;
In our last &lt;a href="http://kitchingroup.cheme.cmu.edu/blog/2016/02/06/Interactive-plots-in-HTML-with-Plotly/"&gt;post&lt;/a&gt; we examined the use of &lt;a href="https://plot.ly/"&gt;plotly&lt;/a&gt; to generate interactive plots in HTML. Today we expand the idea, and use &lt;a href="http://bokeh.pydata.org/en/latest/"&gt;Bokeh&lt;/a&gt; . One potential issue with plotly is the need for an account and API-key, some limitations on how many times a graph can be viewed per day (although I should aspire to have my graphs viewed 1000+ times a day!), and who knows what happens to the graphs if plotly ever goes out of business. While the static images we usually use have limited utility, at least they stick around.
&lt;/p&gt;

&lt;p&gt;
So, today we look at &lt;a href="http://bokeh.pydata.org/en/latest/"&gt;Bokeh&lt;/a&gt; which allows you to embed some json data in your HTML, which is made interactive by your browser with more javascript magic. We get straight to the image here so you can see what this is all about. Briefly, this data shows trends (or lack of) in the adsorption energies of some atoms on the atop and fcc sites of several transition metals as a function of adsorbate coverage  &lt;a class='org-ref-reference' href="#xu-2014-probin-cover"&gt;xu-2014-probin-cover&lt;/a&gt;. The code to do this is found &lt;a href="#sec-1"&gt;here&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Using Bokeh does not integrate real smoothly with my blog workflow, which only generates the body of HTML posts. Bokeh needs some javascript injected into the header to work. To get around that, I show the plot in a frame here. You can see a full HTML version here: &lt;a href="/media/2016-02-07-Interactive-Bokeh-plots-in-HTML/bokeh-plot.html"&gt;bokeh-plot.html&lt;/a&gt; .
&lt;/p&gt;

&lt;iframe src="/media/2016-02-07-Interactive-Bokeh-plots-in-HTML/bokeh-plot.html#figure" width="800" height="700"&gt;&lt;/iframe&gt;

&lt;a name="figure"&gt;&lt;/a&gt;

&lt;div class="plotdiv" id="359fb6b4-4cda-408d-a6c6-4d38f4885edb"&gt;&lt;/div&gt;



&lt;p&gt;
This is somewhat similar to the plotly concept. The data is embedded in the html in this case, which is different. For very large plots, I actually had some trouble exporting the blog post (it was taking a long time to export and I killed it)! I suspect that is a limitation of the org-mode exporter though, because I could save the html files from Python and view them fine. I also noted that having all the javascript in the org-file make font-lock work very slow. It would be better to generate that only on export.
&lt;/p&gt;

&lt;p&gt;
Note to make this work, we need these lines in our HTML header:
&lt;/p&gt;
&lt;pre class="example"&gt;
#+HTML_HEAD: &amp;lt;link rel="stylesheet" href="http://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.css" type="text/css" /&amp;gt;
#+HTML_HEAD: &amp;lt;script type="text/javascript" src="http://cdn.pydata.org/bokeh/release/bokeh-0.11.1.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
Since we do not host those locally, if they ever disappear, our plots will not show ;(
&lt;/p&gt;

&lt;div id="outline-container-sec-1" class="outline-2"&gt;
&lt;h2 id="sec-1"&gt;&lt;a id="ID-47C13034-DBD8-4154-8004-5CABEA2CF1D2" name="ID-47C13034-DBD8-4154-8004-5CABEA2CF1D2"&gt;&lt;/a&gt;&lt;span class="section-number-2"&gt;1&lt;/span&gt; The data and code&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;
&lt;p&gt;
We will get the data from our paper on coverage dependent adsorption energies &lt;a class='org-ref-reference' href="#xu-2014-probin-cover"&gt;xu-2014-probin-cover&lt;/a&gt;. There are some data rich figures there that would benefit from some interactivity. You can get the data here: &lt;a href="http://pubs.acs.org/doi/suppl/10.1021/jp508805h"&gt;http://pubs.acs.org/doi/suppl/10.1021/jp508805h&lt;/a&gt; . Extract out the supporting-information.org and energies.json file to follow here. We will make Figure 2a in the SI document here, and make it interactive with hover tooltips.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python" id="bokeh-plot"&gt;&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; json

&lt;span style="color: #0000FF;"&gt;from&lt;/span&gt; collections &lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; OrderedDict
&lt;span style="color: #0000FF;"&gt;from&lt;/span&gt; bokeh &lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; mpl
&lt;span style="color: #0000FF;"&gt;from&lt;/span&gt; bokeh.plotting &lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; *
&lt;span style="color: #0000FF;"&gt;from&lt;/span&gt; bokeh.models &lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; HoverTool
&lt;span style="color: #0000FF;"&gt;from&lt;/span&gt; bokeh.embed &lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; components

&lt;span style="color: #0000FF;"&gt;with&lt;/span&gt; &lt;span style="color: #006FE0;"&gt;open&lt;/span&gt;(&lt;span style="color: #008000;"&gt;'/users/jkitchin/Desktop/energies.json'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'r'&lt;/span&gt;) &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; f:
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;data&lt;/span&gt; = json.load(f)


&lt;span style="color: #8D8D84;"&gt;# &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;color for metal&lt;/span&gt;
&lt;span style="color: #8D8D84;"&gt;# &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;letter symbol for adsorbate&lt;/span&gt;
&lt;span style="color: #BA36A5;"&gt;colors&lt;/span&gt; = {&lt;span style="color: #008000;"&gt;'Cu'&lt;/span&gt;:&lt;span style="color: #008000;"&gt;'Orange'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; &lt;span style="color: #008000;"&gt;'Ag'&lt;/span&gt;:&lt;span style="color: #008000;"&gt;'Silver'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; &lt;span style="color: #008000;"&gt;'Au'&lt;/span&gt;:&lt;span style="color: #008000;"&gt;'Yellow'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; &lt;span style="color: #008000;"&gt;'Pd'&lt;/span&gt;:&lt;span style="color: #008000;"&gt;'Green'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; &lt;span style="color: #008000;"&gt;'Pt'&lt;/span&gt;:&lt;span style="color: #008000;"&gt;'Red'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; &lt;span style="color: #008000;"&gt;'Rh'&lt;/span&gt;:&lt;span style="color: #008000;"&gt;'Blue'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; &lt;span style="color: #008000;"&gt;'Ir'&lt;/span&gt;:&lt;span style="color: #008000;"&gt;'Purple'&lt;/span&gt;}

&lt;span style="color: #BA36A5;"&gt;all_ads&lt;/span&gt; = [&lt;span style="color: #008000;"&gt;'O'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'S'&lt;/span&gt;]

&lt;span style="color: #BA36A5;"&gt;TOOLS&lt;/span&gt;=&lt;span style="color: #008000;"&gt;"crosshair,pan,wheel_zoom,box_zoom,reset,hover,previewsave"&lt;/span&gt;
&lt;span style="color: #BA36A5;"&gt;p&lt;/span&gt; = figure(title=&lt;span style="color: #008000;"&gt;"Correlation between atop and fcc sites"&lt;/span&gt;, tools=TOOLS)

&lt;span style="color: #0000FF;"&gt;for&lt;/span&gt; metal &lt;span style="color: #0000FF;"&gt;in&lt;/span&gt; [&lt;span style="color: #008000;"&gt;'Rh'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'Pd'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'Cu'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'Ag'&lt;/span&gt;]:
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #0000FF;"&gt;for&lt;/span&gt; adsorbate &lt;span style="color: #0000FF;"&gt;in&lt;/span&gt; all_ads:
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;E1&lt;/span&gt;, &lt;span style="color: #BA36A5;"&gt;E2&lt;/span&gt; = [], []
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #0000FF;"&gt;for&lt;/span&gt; coverage &lt;span style="color: #0000FF;"&gt;in&lt;/span&gt; &lt;span style="color: #008000;"&gt;'0.25'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'0.5'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'0.75'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'1.0'&lt;/span&gt;:
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (&lt;span style="color: #006FE0;"&gt;isinstance&lt;/span&gt;(data[metal][adsorbate][&lt;span style="color: #008000;"&gt;'ontop'&lt;/span&gt;][coverage], &lt;span style="color: #006FE0;"&gt;float&lt;/span&gt;) &lt;span style="color: #0000FF;"&gt;and&lt;/span&gt;
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #006FE0;"&gt;isinstance&lt;/span&gt;(data[metal][adsorbate][&lt;span style="color: #008000;"&gt;'fcc'&lt;/span&gt;][coverage], &lt;span style="color: #006FE0;"&gt;float&lt;/span&gt;)):
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   E1.append(data[metal][adsorbate][&lt;span style="color: #008000;"&gt;'ontop'&lt;/span&gt;][coverage])
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   E2.append(data[metal][adsorbate][&lt;span style="color: #008000;"&gt;'fcc'&lt;/span&gt;][coverage])
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;labels&lt;/span&gt; = [&lt;span style="color: #008000;"&gt;'{0}-{1} {2} ML'&lt;/span&gt;.&lt;span style="color: #006FE0;"&gt;format&lt;/span&gt;(metal, adsorbate, x)
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; &lt;span style="color: #0000FF;"&gt;for&lt;/span&gt; x &lt;span style="color: #0000FF;"&gt;in&lt;/span&gt; [&lt;span style="color: #008000;"&gt;'0.25'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'0.5'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'0.75'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'1.0'&lt;/span&gt;]]
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   p.line(&lt;span style="color: #008000;"&gt;'x'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'y'&lt;/span&gt;, color=colors[metal],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;  source=ColumnDataSource(data={&lt;span style="color: #008000;"&gt;'x'&lt;/span&gt;: E1,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;&lt;span style="color: #008000;"&gt;'y'&lt;/span&gt;: E2,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;&lt;span style="color: #008000;"&gt;'label'&lt;/span&gt;: labels}))
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   p.circle(&lt;span style="color: #008000;"&gt;'x'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'y'&lt;/span&gt;, color=colors[metal],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;  source=ColumnDataSource(data={&lt;span style="color: #008000;"&gt;'x'&lt;/span&gt;: E1,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;&lt;span style="color: #008000;"&gt;'y'&lt;/span&gt;: E2,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;&lt;span style="color: #008000;"&gt;'label'&lt;/span&gt;: labels}))


&lt;span style="color: #BA36A5;"&gt;hover&lt;/span&gt; =p.select({&lt;span style="color: #008000;"&gt;'type'&lt;/span&gt;: HoverTool})
&lt;span style="color: #BA36A5;"&gt;hover.tooltips&lt;/span&gt; = OrderedDict([(&lt;span style="color: #008000;"&gt;"(atop,fcc)"&lt;/span&gt;, &lt;span style="color: #008000;"&gt;"(@x, @y)"&lt;/span&gt;),
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; (&lt;span style="color: #008000;"&gt;"label"&lt;/span&gt;, &lt;span style="color: #008000;"&gt;"@label"&lt;/span&gt;)])

&lt;span style="color: #BA36A5;"&gt;p.xaxis.axis_label&lt;/span&gt; = &lt;span style="color: #008000;"&gt;'Adsorption energy on the atop site'&lt;/span&gt;
&lt;span style="color: #BA36A5;"&gt;p.yaxis.axis_label&lt;/span&gt; = &lt;span style="color: #008000;"&gt;'Adsorption energy on the fcc site'&lt;/span&gt;

&lt;span style="color: #BA36A5;"&gt;script&lt;/span&gt;, &lt;span style="color: #BA36A5;"&gt;div&lt;/span&gt; = components(p)
&lt;span style="color: #BA36A5;"&gt;script&lt;/span&gt; = &lt;span style="color: #008000;"&gt;'\n'&lt;/span&gt;.join([&lt;span style="color: #008000;"&gt;'#+HTML_HEAD_EXTRA: '&lt;/span&gt; + line &lt;span style="color: #0000FF;"&gt;for&lt;/span&gt; line &lt;span style="color: #0000FF;"&gt;in&lt;/span&gt; script.split(&lt;span style="color: #008000;"&gt;'\n'&lt;/span&gt;)])

&lt;span style="color: #0000FF;"&gt;print&lt;/span&gt; &lt;span style="color: #008000;"&gt;'''{script}&lt;/span&gt;

&lt;span style="color: #008000;"&gt;#+BEGIN_HTML&lt;/span&gt;
&lt;span style="color: #008000;"&gt;&amp;lt;a name="figure"&amp;gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000;"&gt;{div}&lt;/span&gt;
&lt;span style="color: #008000;"&gt;#+END_HTML&lt;/span&gt;
&lt;span style="color: #008000;"&gt;'''&lt;/span&gt;.&lt;span style="color: #006FE0;"&gt;format&lt;/span&gt;(script=script, div=div)
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;



&lt;div id="outline-container-sec-2" class="outline-2"&gt;
&lt;h2 id="sec-2"&gt;&lt;span class="section-number-2"&gt;2&lt;/span&gt; References&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-2"&gt;
&lt;p&gt;
&lt;h1 class='org-ref-bib-h1'&gt;Bibliography&lt;/h1&gt;
&lt;ul class='org-ref-bib'&gt;&lt;li&gt;&lt;a id="xu-2014-probin-cover"&gt;[xu-2014-probin-cover] Zhongnan Xu &amp; John Kitchin, Probing the Coverage Dependence of Site and Adsorbate  Configurational Correlations on (111) Surfaces of Late  Transition Metals, &lt;i&gt;J. Phys. Chem. C&lt;/i&gt;, &lt;b&gt;118(44)&lt;/b&gt;, 25597-25602 (2014). &lt;a href="https://doi.org/10.1021/jp508805h"&gt;link&lt;/a&gt;. &lt;a href="https://doi.org/10.1021/jp508805h"&gt;doi&lt;/a&gt;.&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2016 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2016/02/07/Interactive-Bokeh-plots-in-HTML.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;&lt;p&gt;Org-mode version = 8.2.10&lt;/p&gt;
]]></content:encoded>
    </item>
    <item>
      <title>Interactive plots in HTML with Plotly</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2016/02/06/Interactive-plots-in-HTML-with-Plotly</link>
      <pubDate>Sat, 06 Feb 2016 12:44:53 EST</pubDate>
      <category><![CDATA[plotting]]></category>
      <category><![CDATA[interactive]]></category>
      <category><![CDATA[python]]></category>
      <guid isPermaLink="false">vqXGA3yIAkOdEnJx99Y-RLNzOSQ=</guid>
      <description>Interactive plots in HTML with Plotly</description>
      <content:encoded><![CDATA[



&lt;p&gt;
Most of the plots in this blog are static. Today, I look at making them interactive. I will use &lt;a href="https://plot.ly"&gt;https://plot.ly&lt;/a&gt; for this. I want to use some data from a paper we published on the relative stabilities of oxide polymorphs &lt;a class='org-ref-reference' href="#mehta-2015-ident-poten"&gt;mehta-2015-ident-poten&lt;/a&gt;. We will make an interactive figure showing the relative stabilities of the RuO&lt;sub&gt;2&lt;/sub&gt; polymorphs. When you hover on a point, it will show you which polymorph the point refers to. Let's see the figure first here. If you think its interesting read on to see how we made it!
&lt;/p&gt;

&lt;iframe id="igraph" scrolling="no" style="border:none;"seamless="seamless" src="https://plot.ly/~jkitchin/4.embed" height="525" width="100%"&gt;&lt;/iframe&gt;


&lt;p&gt;
We get our data source here: &lt;a href="http://pubs.acs.org/doi/suppl/10.1021/am4059149/suppl_file/am4059149_si_001.pdf"&gt;http://pubs.acs.org/doi/suppl/10.1021/am4059149/suppl_file/am4059149_si_001.pdf&lt;/a&gt; .
&lt;/p&gt;

&lt;p&gt;
Now, we extract the data files:
&lt;/p&gt;
&lt;div class="org-src-container"&gt;

&lt;pre class="src src-sh"&gt;pdftk ~/Desktop/am4059149_si_001.pdf  unpack_files
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
That extracts a json file called supporting-information.json. We use it as suggested in the SI pdf to plot the equations of state for RuO&lt;sub&gt;2&lt;/sub&gt; for several polymorphs.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python" id="ruo2-html"&gt;&lt;span style="color: #8D8D84;"&gt;# &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;coding=utf-8&lt;/span&gt;

&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; plotly.plotly &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; py
&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; plotly.graph_objs &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; go
&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; plotly.tools &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; tls
&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; numpy &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; np

&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; json
&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; plt
&lt;span style="color: #0000FF;"&gt;from&lt;/span&gt; ase.utils.eos &lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; EquationOfState
&lt;span style="color: #0000FF;"&gt;with&lt;/span&gt; &lt;span style="color: #006FE0;"&gt;open&lt;/span&gt;(&lt;span style="color: #008000;"&gt;'supporting-information.json'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'rb'&lt;/span&gt;) &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; f:
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;d&lt;/span&gt; = json.loads(f.read())

&lt;span style="color: #BA36A5;"&gt;BO2&lt;/span&gt; = &lt;span style="color: #008000;"&gt;'RuO2'&lt;/span&gt;
&lt;span style="color: #BA36A5;"&gt;xc&lt;/span&gt; = &lt;span style="color: #008000;"&gt;'PBE'&lt;/span&gt;

&lt;span style="color: #BA36A5;"&gt;layout&lt;/span&gt; = go.Layout(title=&lt;span style="color: #008000;"&gt;'Energy vs. Volume for RuO&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; polymorphs'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;  xaxis=&lt;span style="color: #006FE0;"&gt;dict&lt;/span&gt;(title=&lt;span style="color: #008000;"&gt;'Volume (&amp;#197;&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;)'&lt;/span&gt;),
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;  yaxis=&lt;span style="color: #006FE0;"&gt;dict&lt;/span&gt;(title=&lt;span style="color: #008000;"&gt;'Energy (eV)'&lt;/span&gt;))

&lt;span style="color: #BA36A5;"&gt;traces&lt;/span&gt; = []

&lt;span style="color: #0000FF;"&gt;for&lt;/span&gt; polymorph &lt;span style="color: #0000FF;"&gt;in&lt;/span&gt; [&lt;span style="color: #008000;"&gt;'rutile'&lt;/span&gt;,&lt;span style="color: #008000;"&gt;'anatase'&lt;/span&gt;,&lt;span style="color: #008000;"&gt;'brookite'&lt;/span&gt;,&lt;span style="color: #008000;"&gt;'columbite'&lt;/span&gt;,&lt;span style="color: #008000;"&gt;'pyrite'&lt;/span&gt;,&lt;span style="color: #008000;"&gt;'fluorite'&lt;/span&gt;]:

&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #8D8D84;"&gt;# &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;number of atoms in the unit cell - used to normalize&lt;/span&gt;
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;natoms&lt;/span&gt;= &lt;span style="color: #006FE0;"&gt;len&lt;/span&gt;(d[BO2][polymorph][xc][&lt;span style="color: #008000;"&gt;'EOS'&lt;/span&gt;][&lt;span style="color: #008000;"&gt;'calculations'&lt;/span&gt;]
                [0][&lt;span style="color: #008000;"&gt;'atoms'&lt;/span&gt;][&lt;span style="color: #008000;"&gt;'symbols'&lt;/span&gt;])
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;volumes&lt;/span&gt; = [entry[&lt;span style="color: #008000;"&gt;'data'&lt;/span&gt;][&lt;span style="color: #008000;"&gt;'volume'&lt;/span&gt;]*3./natoms &lt;span style="color: #0000FF;"&gt;for&lt;/span&gt; entry &lt;span style="color: #0000FF;"&gt;in&lt;/span&gt;
               d[BO2][polymorph][xc][&lt;span style="color: #008000;"&gt;'EOS'&lt;/span&gt;][&lt;span style="color: #008000;"&gt;'calculations'&lt;/span&gt;]]
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;energies&lt;/span&gt; =  [entry[&lt;span style="color: #008000;"&gt;'data'&lt;/span&gt;][&lt;span style="color: #008000;"&gt;'total_energy'&lt;/span&gt;]*3./natoms &lt;span style="color: #0000FF;"&gt;for&lt;/span&gt; entry &lt;span style="color: #0000FF;"&gt;in&lt;/span&gt;
                 d[BO2][polymorph][xc][&lt;span style="color: #008000;"&gt;'EOS'&lt;/span&gt;][&lt;span style="color: #008000;"&gt;'calculations'&lt;/span&gt;]]

&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;trace&lt;/span&gt; = go.Scatter(x=np.array(volumes),
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;  y=np.array(energies),
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;  mode=&lt;span style="color: #008000;"&gt;'lines+markers'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;  name=polymorph,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;  text=polymorph)

&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;traces&lt;/span&gt; += [trace]

&lt;span style="color: #BA36A5;"&gt;fig&lt;/span&gt; = go.Figure(data=traces, layout=layout)
&lt;span style="color: #BA36A5;"&gt;plot_url&lt;/span&gt; = py.plot(fig, filename=&lt;span style="color: #008000;"&gt;'ruo2-2'&lt;/span&gt;)

&lt;span style="color: #0000FF;"&gt;print&lt;/span&gt; tls.get_embed(plot_url)
&lt;/pre&gt;
&lt;/div&gt;




&lt;p&gt;
Pretty nice, now we should have an interactive plot in our browser with the data points labeled with tags, zooming, etc&amp;#x2026; That is nice for the blog. It isn't so nice for daily work, as there is no visual version of the plot in my org-file. Of course, I can visit the url to see the plot in my browser, it is just different from what I am used to. For everyone else, this is probably better. It looks like you can actually get the data from the web page, including some minimal analysis like regression, and save your view to an image! That could be pretty nice for some data sets.
&lt;/p&gt;

&lt;div id="outline-container-sec-1" class="outline-2"&gt;
&lt;h2 id="sec-1"&gt;&lt;span class="section-number-2"&gt;1&lt;/span&gt; Using Plotly yourself&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;
&lt;p&gt;
First, go to &lt;a href="https://plot.ly"&gt;https://plot.ly&lt;/a&gt; and sign up for an account. You will want to register your API key like this, which will save it in a file for your convenience. Then you can do things like I did above too.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; plotly.tools &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; tls
tls.set_credentials_file(username=&lt;span style="color: #008000;"&gt;'jkitchin'&lt;/span&gt;, api_key=&lt;span style="color: #008000;"&gt;'xxxxxxx'&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-sec-2" class="outline-2"&gt;
&lt;h2 id="sec-2"&gt;&lt;span class="section-number-2"&gt;2&lt;/span&gt; References&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-2"&gt;
&lt;p&gt;
&lt;h1 class='org-ref-bib-h1'&gt;Bibliography&lt;/h1&gt;
&lt;ul class='org-ref-bib'&gt;&lt;li&gt;&lt;a id="mehta-2015-ident-poten"&gt;[mehta-2015-ident-poten] Prateek Mehta, Paul Salvador &amp; John Kitchin, Identifying Potential \ceBO2 Oxide Polymorphs for Epitaxial  Growth Candidates, &lt;i&gt;ACS Appl. Mater. Interfaces&lt;/i&gt;, &lt;b&gt;6(5)&lt;/b&gt;, 3630-3639 (2015). &lt;a href="https://doi.org/10.1021/am4059149"&gt;link&lt;/a&gt;. &lt;a href="https://doi.org/10.1021/am4059149"&gt;doi&lt;/a&gt;.&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2016 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2016/02/06/Interactive-plots-in-HTML-with-Plotly.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;&lt;p&gt;Org-mode version = 8.2.10&lt;/p&gt;
]]></content:encoded>
    </item>
    <item>
      <title>Hatched symbols in matplotlib</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2013/10/26/Hatched-symbols-in-matplotlib</link>
      <pubDate>Sat, 26 Oct 2013 14:35:19 EDT</pubDate>
      <category><![CDATA[plotting]]></category>
      <guid isPermaLink="false">vgEHd0mA2-E06J4RXLrbrI7d1z4=</guid>
      <description>Hatched symbols in matplotlib</description>
      <content:encoded><![CDATA[


&lt;p&gt;
I learned something new about matplotlib today: How to make hatched (patterned) symbols in a plot. Well, sort of. The scatter plot in matplotlib has a hatch keyword argument that specifies a pattern on the marker. Below, is an example that runs through a handful of hatch patterns, on randomly selected symbols.
&lt;/p&gt;

&lt;p&gt;
Curiously, hatch is not a kwarg of the scatter function, but of &lt;a href="http://matplotlib.org/api/collections_api.html#matplotlib.collections.Collection.set_hatch"&gt;collections&lt;/a&gt; . Anyway, let us see how to get the hatched symbols.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; random
&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; numpy &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; np
&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; plt

&lt;span style="color: #8b008b;"&gt;patterns&lt;/span&gt; = (&lt;span style="color: #228b22;"&gt;'-'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'+'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'x'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'\\'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'*'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'o'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'O'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'.'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'/'&lt;/span&gt;)
&lt;span style="color: #8b008b;"&gt;markers&lt;/span&gt; = &lt;span style="color: #228b22;"&gt;'os&amp;lt;^&amp;gt;p*'&lt;/span&gt;
&lt;span style="color: #8b0000;"&gt;for&lt;/span&gt; pattern &lt;span style="color: #8b0000;"&gt;in&lt;/span&gt; patterns:
    plt.scatter(np.random.uniform(size=(3,1)), np.random.uniform(size=(3,1)), s=1000,
                marker=random.choice(markers),
                facecolor=&lt;span style="color: #228b22;"&gt;'white'&lt;/span&gt;,
                hatch=3*pattern, label=pattern)

plt.legend(scatterpoints=1, loc=&lt;span style="color: #228b22;"&gt;'best'&lt;/span&gt;)
plt.savefig(&lt;span style="color: #228b22;"&gt;'images/hatched-symbols.png'&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;


&lt;div class="figure"&gt;
&lt;p&gt;&lt;img src="/media/2013-10-26-Hatched-symbols-in-matplotlib/hatched-symbols.png"&gt; 
&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
There are some other interesting things you can do with &lt;a href="http://matplotlib.org/examples/pylab_examples/filledmarker_demo.html"&gt;filled markers&lt;/a&gt; , &lt;a href="http://matplotlib.org/examples/pylab_examples/contourf_hatching.html"&gt;hatched contours&lt;/a&gt; and with &lt;a href="http://matplotlib.org/examples/pylab_examples/hatch_demo.html"&gt;hatched bar graphs&lt;/a&gt; . Note this hatching is specific to plt.scatter. It does not work with plt.plot.
&lt;/p&gt;
&lt;p&gt;Copyright (C) 2013 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2013/10/26/Hatched-symbols-in-matplotlib.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;]]></content:encoded>
    </item>
    <item>
      <title>Customizing plots after the fact</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2013/09/16/Customizing-plots-after-the-fact</link>
      <pubDate>Mon, 16 Sep 2013 16:27:27 EDT</pubDate>
      <category><![CDATA[plotting]]></category>
      <guid isPermaLink="false">pBVsmPybKgu37T7IRa7Zaf5Bdfw=</guid>
      <description>Customizing plots after the fact</description>
      <content:encoded><![CDATA[


&lt;p&gt;
&lt;a href="http://matlab.cheme.cmu.edu/2011/09/16/customizing-plots-after-the-fact/"&gt;Matlab post&lt;/a&gt;
Sometimes it is desirable to make a plot that shows the data you want to present, and to customize the details, e.g. font size/type and line thicknesses afterwards. It can be tedious to try to add the customization code to the existing code that makes the plot. Today, we look at a way to do the customization after the plot is created.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; numpy &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; np
&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; plt

&lt;span style="color: #8b008b;"&gt;x&lt;/span&gt; = np.linspace(0,2)
&lt;span style="color: #8b008b;"&gt;y1&lt;/span&gt; = x
&lt;span style="color: #8b008b;"&gt;y2&lt;/span&gt; = x**2
&lt;span style="color: #8b008b;"&gt;y3&lt;/span&gt; = x**3

plt.plot(x, y1, x, y2, x, y3)
&lt;span style="color: #8b008b;"&gt;xL&lt;/span&gt; = plt.xlabel(&lt;span style="color: #228b22;"&gt;'x'&lt;/span&gt;)
&lt;span style="color: #8b008b;"&gt;yL&lt;/span&gt; = plt.ylabel(&lt;span style="color: #228b22;"&gt;'f(x)'&lt;/span&gt;)
plt.title(&lt;span style="color: #228b22;"&gt;'plots of y = x^n'&lt;/span&gt;)
plt.legend([&lt;span style="color: #228b22;"&gt;'x'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'x^2'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'x^3'&lt;/span&gt;], loc=&lt;span style="color: #228b22;"&gt;'best'&lt;/span&gt;)
plt.savefig(&lt;span style="color: #228b22;"&gt;'images/after-customization-1.png'&lt;/span&gt;)

&lt;span style="color: #8b008b;"&gt;fig&lt;/span&gt; = plt.gcf()

plt.setp(fig, &lt;span style="color: #228b22;"&gt;'size_inches'&lt;/span&gt;, (4, 6))
plt.savefig(&lt;span style="color: #228b22;"&gt;'images/after-customization-2.png'&lt;/span&gt;)


&lt;span style="color: #ff0000; font-weight: bold;"&gt;# &lt;/span&gt;&lt;span style="color: #ff0000; font-weight: bold;"&gt;set lines to dashed&lt;/span&gt;
&lt;span style="color: #8b0000;"&gt;from&lt;/span&gt; matplotlib.lines &lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; Line2D
&lt;span style="color: #8b0000;"&gt;for&lt;/span&gt; o &lt;span style="color: #8b0000;"&gt;in&lt;/span&gt; fig.findobj(Line2D):
    o.set_linestyle(&lt;span style="color: #228b22;"&gt;'--'&lt;/span&gt;)

&lt;span style="color: #ff0000; font-weight: bold;"&gt;#&lt;/span&gt;&lt;span style="color: #ff0000; font-weight: bold;"&gt;set(allaxes,'FontName','Arial','FontWeight','Bold','LineWidth',2,'FontSize',14);&lt;/span&gt;

&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; matplotlib.text &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; text
&lt;span style="color: #8b0000;"&gt;for&lt;/span&gt; o &lt;span style="color: #8b0000;"&gt;in&lt;/span&gt; fig.findobj(text.Text):
    plt.setp(o, &lt;span style="color: #228b22;"&gt;'fontname'&lt;/span&gt;,&lt;span style="color: #228b22;"&gt;'Arial'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'fontweight'&lt;/span&gt;,&lt;span style="color: #228b22;"&gt;'bold'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'fontsize'&lt;/span&gt;, 14)

plt.setp(xL, &lt;span style="color: #228b22;"&gt;'fontstyle'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'italic'&lt;/span&gt;)
plt.setp(yL, &lt;span style="color: #228b22;"&gt;'fontstyle'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'italic'&lt;/span&gt;)
plt.savefig(&lt;span style="color: #228b22;"&gt;'images/after-customization-3.png'&lt;/span&gt;)
plt.show()
&lt;/pre&gt;
&lt;/div&gt;


&lt;div class="figure"&gt;
&lt;p&gt;&lt;p&gt;&lt;img src="/img/./images/after-customization-1.png"&gt;&lt;p&gt;
&lt;/p&gt;
&lt;/div&gt;


&lt;div class="figure"&gt;
&lt;p&gt;&lt;p&gt;&lt;img src="/img/./images/after-customization-2.png"&gt;&lt;p&gt;
&lt;/p&gt;
&lt;/div&gt;


&lt;div class="figure"&gt;
&lt;p&gt;&lt;p&gt;&lt;img src="/img/./images/after-customization-3.png"&gt;&lt;p&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2013 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2013/09/16/Customizing-plots-after-the-fact.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;]]></content:encoded>
    </item>
    <item>
      <title>Plotting two datasets with very different scales</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2013/09/13/Plotting-two-datasets-with-very-different-scales</link>
      <pubDate>Fri, 13 Sep 2013 13:55:20 EDT</pubDate>
      <category><![CDATA[plotting]]></category>
      <guid isPermaLink="false">hCev9SfA5FsJGEh4szmWwZwN_hw=</guid>
      <description>Plotting two datasets with very different scales</description>
      <content:encoded><![CDATA[


&lt;div id="table-of-contents"&gt;
&lt;h2&gt;Table of Contents&lt;/h2&gt;
&lt;div id="text-table-of-contents"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#sec-1"&gt;1. Make two plots!&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#sec-2"&gt;2. Scaling the results&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#sec-3"&gt;3. Double-y axis plot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#sec-4"&gt;4. Subplots&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;a href="http://matlab.cheme.cmu.edu/2011/08/25/plotting-two-datasets-with-very-different-scales/"&gt;Matlab plot&lt;/a&gt; 
&lt;/p&gt;

&lt;p&gt;
Sometimes you will have two datasets you want to plot together, but the scales will be so different it is hard to seem them both in the same plot. Here we examine a few strategies to plotting this kind of data.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2*np.pi)
y1 = np.sin(x);
y2 = 0.01 * np.cos(x);

plt.plot(x, y1, x, y2)
plt.legend(['y1', 'y2'])
plt.savefig('images/two-scales-1.png')
# in this plot y2 looks almost flat!
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
&amp;gt;&amp;gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; [&amp;lt;matplotlib.lines.Line2D object at 0x0000000006089128&amp;gt;, &amp;lt;matplotlib.lines.Line2D object at 0x000000000766B2E8&amp;gt;]
&amp;lt;matplotlib.legend.Legend object at 0x0000000007661668&amp;gt;
&lt;/pre&gt;


&lt;div class="figure"&gt;
&lt;p&gt;&lt;img src="/media/2013-09-13-Plotting-two-datasets-with-very-different-scales/two-scales-1.png"&gt; 
&lt;/p&gt;
&lt;/div&gt;

&lt;div id="outline-container-sec-1" class="outline-2"&gt;
&lt;h2 id="sec-1"&gt;&lt;span class="section-number-2"&gt;1&lt;/span&gt; Make two plots!&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;
&lt;p&gt;
this certainly solves the problem, but you have two full size plots, which can take up a lot of space in a presentation and report. Often your goal in plotting both data sets is to compare them, and it is easiest to compare plots when they are perfectly lined up. Doing that manually can be tedious.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;plt.figure()
plt.plot(x,y1)
plt.legend(['y1'])
plt.savefig('images/two-scales-2.png')

plt.figure()
plt.plot(x,y2)
plt.legend(['y2'])
plt.savefig('images/two-scales-3.png')
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
&amp;lt;matplotlib.figure.Figure object at 0x0000000007D45438&amp;gt;
[&amp;lt;matplotlib.lines.Line2D object at 0x00000000081C61D0&amp;gt;]
&amp;lt;matplotlib.legend.Legend object at 0x0000000007FA1CF8&amp;gt;
&amp;gt;&amp;gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; &amp;lt;matplotlib.figure.Figure object at 0x00000000081C63C8&amp;gt;
[&amp;lt;matplotlib.lines.Line2D object at 0x00000000081C8F60&amp;gt;]
&amp;lt;matplotlib.legend.Legend object at 0x00000000081D7278&amp;gt;
&lt;/pre&gt;


&lt;div class="figure"&gt;
&lt;p&gt;&lt;img src="/media/2013-09-13-Plotting-two-datasets-with-very-different-scales/two-scales-2.png"&gt; 
&lt;/p&gt;
&lt;/div&gt;


&lt;div class="figure"&gt;
&lt;p&gt;&lt;img src="/media/2013-09-13-Plotting-two-datasets-with-very-different-scales/two-scales-3.png"&gt; 
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-sec-2" class="outline-2"&gt;
&lt;h2 id="sec-2"&gt;&lt;span class="section-number-2"&gt;2&lt;/span&gt; Scaling the results&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-2"&gt;
&lt;p&gt;
Sometimes you can scale one dataset so it has a similar magnitude as the other data set. Here we could multiply y2 by 100, and then it will be similar in size to y1. Of course, you need to indicate that y2 has been scaled in the graph somehow. Here we use the legend.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;plt.figure()
plt.plot(x, y1, x, 100 * y2)
plt.legend(['y1', '100*y2'])
plt.savefig('images/two-scales-4.png')
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
&amp;lt;matplotlib.figure.Figure object at 0x0000000007FA7908&amp;gt;
[&amp;lt;matplotlib.lines.Line2D object at 0x000000000B0285C0&amp;gt;, &amp;lt;matplotlib.lines.Line2D object at 0x000000000B0287B8&amp;gt;]
&amp;lt;matplotlib.legend.Legend object at 0x000000000B028C88&amp;gt;
&lt;/pre&gt;


&lt;div class="figure"&gt;
&lt;p&gt;&lt;img src="/media/2013-09-13-Plotting-two-datasets-with-very-different-scales/two-scales-4.png"&gt; 
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-sec-3" class="outline-2"&gt;
&lt;h2 id="sec-3"&gt;&lt;span class="section-number-2"&gt;3&lt;/span&gt; Double-y axis plot&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-3"&gt;
&lt;p&gt;

&lt;/p&gt;

&lt;p&gt;
Using two separate y-axes can solve your scaling problem. Note that each y-axis is color coded to the data. It can be difficult to read these graphs when printed in black and white
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(x, y1)
ax1.set_ylabel('y1')

ax2 = ax1.twinx()
ax2.plot(x, y2, 'r-')
ax2.set_ylabel('y2', color='r')
for tl in ax2.get_yticklabels():
    tl.set_color('r')

plt.savefig('images/two-scales-5.png')
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
&amp;gt;&amp;gt;&amp;gt; [&amp;lt;matplotlib.lines.Line2D object at 0x000000000BA34208&amp;gt;]
&amp;lt;matplotlib.text.Text object at 0x000000000BA37C50&amp;gt;
&amp;gt;&amp;gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; [&amp;lt;matplotlib.lines.Line2D object at 0x000000000BA4DEF0&amp;gt;]
&amp;lt;matplotlib.text.Text object at 0x000000000BA594A8&amp;gt;
&lt;/pre&gt;



&lt;div class="figure"&gt;
&lt;p&gt;&lt;img src="/media/2013-09-13-Plotting-two-datasets-with-very-different-scales/two-scales-5.png"&gt; 
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;div id="outline-container-sec-4" class="outline-2"&gt;
&lt;h2 id="sec-4"&gt;&lt;span class="section-number-2"&gt;4&lt;/span&gt; Subplots&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-4"&gt;
&lt;p&gt;

An alternative approach to double y axes is to use subplots. 
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;plt.figure()
f, axes = plt.subplots(2, 1)
axes[0].plot(x, y1)
axes[0].set_ylabel('y1')

axes[1].plot(x, y2)
axes[1].set_ylabel('y2')
plt.savefig('images/two-scales-6.png')
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
&amp;lt;matplotlib.figure.Figure object at 0x000000000BDC47B8&amp;gt;
&amp;gt;&amp;gt;&amp;gt; [&amp;lt;matplotlib.lines.Line2D object at 0x000000000BDE2F28&amp;gt;]
&amp;lt;matplotlib.text.Text object at 0x000000000BDD74E0&amp;gt;
&amp;gt;&amp;gt;&amp;gt; [&amp;lt;matplotlib.lines.Line2D object at 0x000000000D05E748&amp;gt;]
&amp;lt;matplotlib.text.Text object at 0x000000000BDEC438&amp;gt;
&lt;/pre&gt;


&lt;div class="figure"&gt;
&lt;p&gt;&lt;img src="/media/2013-09-13-Plotting-two-datasets-with-very-different-scales/two-scales-6.png"&gt; 
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2014 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2013/09/13/Plotting-two-datasets-with-very-different-scales.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;&lt;p&gt;Org-mode version = 8.2.6&lt;/p&gt;]]></content:encoded>
    </item>
    <item>
      <title>Picasso's short lived blue period with Python</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2013/03/04/Picasso-s-short-lived-blue-period-with-Python</link>
      <pubDate>Mon, 04 Mar 2013 16:07:55 EST</pubDate>
      <category><![CDATA[plotting]]></category>
      <guid isPermaLink="false">ZzQ8qGFQfCRpROKf2Y-FF8XiTsg=</guid>
      <description>Picasso's short lived blue period with Python</description>
      <content:encoded><![CDATA[


&lt;p&gt;
&lt;a href="http://matlab.cheme.cmu.edu/2011/09/14/picassos-short-lived-blue-period-with-matlab/"&gt;Matlab post&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
It is an unknown fact that Picasso had a brief blue plotting period with Matlab before moving on to his more famous paintings. It started from irritation with the default colors available in Matlab for plotting. After watching his friend van Gogh cut off his own ear out of frustration with the ugly default colors, Picasso had to do something different.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-python"&gt;&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; numpy &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; np
&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; plt

&lt;span style="color: #8D8D84;"&gt;#&lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;this plots horizontal lines for each y value of m.&lt;/span&gt;
&lt;span style="color: #0000FF;"&gt;for&lt;/span&gt; m &lt;span style="color: #0000FF;"&gt;in&lt;/span&gt; np.linspace(1, 50, 100):
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   plt.plot([0, 50], [m, m])

plt.savefig(&lt;span style="color: #008000;"&gt;'images/blues-1.png'&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
&lt;img src="/media/blues-1.png"&gt; 
&lt;/p&gt;

&lt;p&gt;
Picasso copied the table available at &lt;a href="http://en.wikipedia.org/wiki/List_of_colors"&gt;http://en.wikipedia.org/wiki/List_of_colors&lt;/a&gt; and parsed it into a dictionary of hex codes for new colors. That allowed him to specify a list of beautiful blues for his graph. Picasso eventually gave up on python as an artform, and moved on to painting.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;
&lt;pre class="src src-python"&gt;&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; numpy &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; np
&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; plt

&lt;span style="color: #BA36A5;"&gt;c&lt;/span&gt; = {}
&lt;span style="color: #0000FF;"&gt;with&lt;/span&gt; &lt;span style="color: #006FE0;"&gt;open&lt;/span&gt;(&lt;span style="color: #008000;"&gt;'color.table'&lt;/span&gt;) &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; f:
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #0000FF;"&gt;for&lt;/span&gt; line &lt;span style="color: #0000FF;"&gt;in&lt;/span&gt; f:
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;fields&lt;/span&gt; = line.split(&lt;span style="color: #008000;"&gt;'\t'&lt;/span&gt;)
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;colorname&lt;/span&gt; = fields[0].lower()
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;hexcode&lt;/span&gt; = fields[1]
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #BA36A5;"&gt;c&lt;/span&gt;[colorname] = hexcode

&lt;span style="color: #BA36A5;"&gt;names&lt;/span&gt; = c.keys()
&lt;span style="color: #BA36A5;"&gt;names&lt;/span&gt; = &lt;span style="color: #006FE0;"&gt;sorted&lt;/span&gt;(names)

&lt;span style="color: #0000FF;"&gt;print&lt;/span&gt;(names)

&lt;span style="color: #BA36A5;"&gt;blues&lt;/span&gt; = [c[&lt;span style="color: #008000;"&gt;'alice blue'&lt;/span&gt;],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;c[&lt;span style="color: #008000;"&gt;'light blue'&lt;/span&gt;],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;c[&lt;span style="color: #008000;"&gt;'baby blue'&lt;/span&gt;],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;c[&lt;span style="color: #008000;"&gt;'light sky blue'&lt;/span&gt;],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;c[&lt;span style="color: #008000;"&gt;'maya blue'&lt;/span&gt;],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;c[&lt;span style="color: #008000;"&gt;'cornflower blue'&lt;/span&gt;],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;c[&lt;span style="color: #008000;"&gt;'bleu de france'&lt;/span&gt;],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;c[&lt;span style="color: #008000;"&gt;'azure'&lt;/span&gt;],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;c[&lt;span style="color: #008000;"&gt;'blue sapphire'&lt;/span&gt;],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;c[&lt;span style="color: #008000;"&gt;'cobalt'&lt;/span&gt;],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;c[&lt;span style="color: #008000;"&gt;'blue'&lt;/span&gt;],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;c[&lt;span style="color: #008000;"&gt;'egyptian blue'&lt;/span&gt;],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;c[&lt;span style="color: #008000;"&gt;'duke blue'&lt;/span&gt;]]

&lt;span style="color: #BA36A5;"&gt;ax&lt;/span&gt; = plt.gca()
ax.set_color_cycle(blues)

&lt;span style="color: #8D8D84;"&gt;#&lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;this plots horizontal lines for each y value of m.&lt;/span&gt;
&lt;span style="color: #0000FF;"&gt;for&lt;/span&gt; i, m &lt;span style="color: #0000FF;"&gt;in&lt;/span&gt; &lt;span style="color: #006FE0;"&gt;enumerate&lt;/span&gt;(np.linspace(1, 50, 100)):
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   plt.plot([0, 50], [m, m])

plt.savefig(&lt;span style="color: #008000;"&gt;'images/blues-2.png'&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
['aero', 'aero blue', 'african violet', 'air force blue (raf)', 'air force blue (usaf)', 'air superiority blue', 'alabama crimson', 'alice blue', 'alizarin crimson', 'alloy orange', 'almond', 'amaranth', 'amazon', 'amber', 'american rose', 'amethyst', 'android green', 'anti-flash white', 'antique brass', 'antique bronze', 'antique fuchsia', 'antique ruby', 'antique white', 'ao (english)', 'apple green', 'apricot', 'aqua', 'aquamarine', 'army green', 'arsenic', 'arylide yellow', 'ash grey', 'asparagus', 'atomic tangerine', 'auburn', 'aureolin', 'aurometalsaurus', 'avocado', 'azure', 'azure mist/web', "b'dazzled blue", 'baby blue', 'baby blue eyes', 'baby pink', 'baby powder', 'baker-miller pink', 'ball blue', 'banana mania', 'banana yellow', 'barbie pink', 'barn red', 'battleship grey', 'bazaar', 'beau blue', 'beaver', 'beige', 'big dip o’ruby', 'bisque', 'bistre', 'bistre brown', 'bitter lemon', 'bitter lime', 'bittersweet', 'bittersweet shimmer', 'black', 'black bean', 'black leather jacket', 'black olive', 'blanched almond', 'blast-off bronze', 'bleu de france', 'blizzard blue', 'blond', 'blue', 'blue (crayola)', 'blue (munsell)', 'blue (ncs)', 'blue (pigment)', 'blue (ryb)', 'blue bell', 'blue sapphire', 'blue yonder', 'blue-gray', 'blue-green', 'blue-violet', 'blueberry', 'bluebonnet', 'blush', 'bole', 'bondi blue', 'bone', 'boston university red', 'bottle green', 'boysenberry', 'brandeis blue', 'brass', 'brick red', 'bright cerulean', 'bright green', 'bright lavender', 'bright maroon', 'bright pink', 'bright turquoise', 'bright ube', 'brilliant lavender', 'brilliant rose', 'brink pink', 'british racing green', 'bronze', 'bronze yellow', 'brown (traditional)', 'brown (web)', 'brown-nose', 'brunswick green', 'bubble gum', 'bubbles', 'buff', 'bulgarian rose', 'burgundy', 'burlywood', 'burnt orange', 'burnt sienna', 'burnt umber', 'byzantine', 'byzantium', 'cadet', 'cadet blue', 'cadet grey', 'cadmium green', 'cadmium orange', 'cadmium red', 'cadmium yellow', 'café au lait', 'café noir', 'cal poly green', 'cambridge blue', 'camel', 'cameo pink', 'camouflage green', 'canary yellow', 'candy apple red', 'candy pink', 'capri', 'caput mortuum', 'cardinal', 'caribbean green', 'carmine', 'carmine (m&amp;amp;p)', 'carmine pink', 'carmine red', 'carnation pink', 'carnelian', 'carolina blue', 'carrot orange', 'castleton green', 'catalina blue', 'catawba', 'cedar chest', 'ceil', 'celadon', 'celadon blue', 'celadon green', 'celeste (colour)', 'celestial blue', 'cerise', 'cerise pink', 'cerulean', 'cerulean blue', 'cerulean frost', 'cg blue', 'cg red', 'chamoisee', 'champagne', 'charcoal', 'charleston green', 'charm pink', 'chartreuse (traditional)', 'chartreuse (web)', 'cherry', 'cherry blossom pink', 'chestnut', 'china pink', 'china rose', 'chinese red', 'chinese violet', 'chocolate (traditional)', 'chocolate (web)', 'chrome yellow', 'cinereous', 'cinnabar', 'cinnamon', 'citrine', 'citron', 'claret', 'classic rose', 'cobalt', 'cocoa brown', 'coconut', 'coffee', 'columbia blue', 'congo pink', 'cool black', 'cool grey', 'copper', 'copper (crayola)', 'copper penny', 'copper red', 'copper rose', 'coquelicot', 'coral', 'coral pink', 'coral red', 'cordovan', 'corn', 'cornell red', 'cornflower blue', 'cornsilk', 'cosmic latte', 'cotton candy', 'cream', 'crimson', 'crimson glory', 'cyan', 'cyan (process)', 'cyber grape', 'cyber yellow', 'daffodil', 'dandelion', 'dark blue', 'dark blue-gray', 'dark brown', 'dark byzantium', 'dark candy apple red', 'dark cerulean', 'dark chestnut', 'dark coral', 'dark cyan', 'dark electric blue', 'dark goldenrod', 'dark gray', 'dark green', 'dark imperial blue', 'dark jungle green', 'dark khaki', 'dark lava', 'dark lavender', 'dark liver', 'dark liver (horses)', 'dark magenta', 'dark midnight blue', 'dark moss green', 'dark olive green', 'dark orange', 'dark orchid', 'dark pastel blue', 'dark pastel green', 'dark pastel purple', 'dark pastel red', 'dark pink', 'dark powder blue', 'dark raspberry', 'dark red', 'dark salmon', 'dark scarlet', 'dark sea green', 'dark sienna', 'dark sky blue', 'dark slate blue', 'dark slate gray', 'dark spring green', 'dark tan', 'dark tangerine', 'dark taupe', 'dark terra cotta', 'dark turquoise', 'dark vanilla', 'dark violet', 'dark yellow', 'dartmouth green', "davy's grey", 'debian red', 'deep carmine', 'deep carmine pink', 'deep carrot orange', 'deep cerise', 'deep champagne', 'deep chestnut', 'deep coffee', 'deep fuchsia', 'deep jungle green', 'deep lemon', 'deep lilac', 'deep magenta', 'deep mauve', 'deep moss green', 'deep peach', 'deep pink', 'deep ruby', 'deep saffron', 'deep sky blue', 'deep space sparkle', 'deep taupe', 'deep tuscan red', 'deer', 'denim', 'desert', 'desert sand', 'diamond', 'dim gray', 'dirt', 'dodger blue', 'dogwood rose', 'dollar bill', 'donkey brown', 'drab', 'duke blue', 'dust storm', 'earth yellow', 'ebony', 'ecru', 'eggplant', 'eggshell', 'egyptian blue', 'electric blue', 'electric crimson', 'electric cyan', 'electric green', 'electric indigo', 'electric lavender', 'electric lime', 'electric purple', 'electric ultramarine', 'electric violet', 'electric yellow', 'emerald', 'english green', 'english lavender', 'english red', 'english violet', 'eton blue', 'eucalyptus', 'fallow', 'falu red', 'fandango', 'fandango pink', 'fashion fuchsia', 'fawn', 'feldgrau', 'feldspar', 'fern green', 'ferrari red', 'field drab', 'fire engine red', 'firebrick', 'flame', 'flamingo pink', 'flattery', 'flavescent', 'flax', 'flirt', 'floral white', 'fluorescent orange', 'fluorescent pink', 'fluorescent yellow', 'folly', 'forest green (traditional)', 'forest green (web)', 'french beige', 'french bistre', 'french blue', 'french lilac', 'french lime', 'french mauve', 'french raspberry', 'french rose', 'french sky blue', 'french wine', 'fresh air', 'fuchsia', 'fuchsia (crayola)', 'fuchsia pink', 'fuchsia rose', 'fulvous', 'fuzzy wuzzy', 'gainsboro', 'gamboge', 'ghost white', 'giants orange', 'ginger', 'glaucous', 'glitter', 'go green', 'gold (metallic)', 'gold (web) (golden)', 'gold fusion', 'golden brown', 'golden poppy', 'golden yellow', 'goldenrod', 'granny smith apple', 'grape', 'gray', 'gray (html/css gray)', 'gray (x11 gray)', 'gray-asparagus', 'gray-blue', 'green (color wheel) (x11 green)', 'green (crayola)', 'green (html/css color)', 'green (munsell)', 'green (ncs)', 'green (pigment)', 'green (ryb)', 'green-yellow', 'grullo', 'guppie green', 'halayà úbe', 'han blue', 'han purple', 'hansa yellow', 'harlequin', 'harvard crimson', 'harvest gold', 'heart gold', 'heliotrope', 'hollywood cerise', 'honeydew', 'honolulu blue', "hooker's green", 'hot magenta', 'hot pink', 'hunter green', 'iceberg', 'icterine', 'illuminating emerald', 'imperial', 'imperial blue', 'imperial purple', 'imperial red', 'inchworm', 'india green', 'indian red', 'indian yellow', 'indigo', 'indigo (dye)', 'indigo (web)', 'international klein blue', 'international orange (aerospace)', 'international orange (engineering)', 'international orange (golden gate bridge)', 'iris', 'irresistible', 'isabelline', 'islamic green', 'italian sky blue', 'ivory', 'jade', 'japanese indigo', 'japanese violet', 'jasmine', 'jasper', 'jazzberry jam', 'jelly bean', 'jet', 'jonquil', 'june bud', 'jungle green', 'kelly green', 'kenyan copper', 'keppel', 'khaki (html/css) (khaki)', 'khaki (x11) (light khaki)', 'kobe', 'kobi', 'ku crimson', 'la salle green', 'languid lavender', 'lapis lazuli', 'laser lemon', 'laurel green', 'lava', 'lavender (floral)', 'lavender (web)', 'lavender blue', 'lavender blush', 'lavender gray', 'lavender indigo', 'lavender magenta', 'lavender mist', 'lavender pink', 'lavender purple', 'lavender rose', 'lawn green', 'lemon', 'lemon chiffon', 'lemon curry', 'lemon glacier', 'lemon lime', 'lemon meringue', 'lemon yellow', 'licorice', 'light apricot', 'light blue', 'light brown', 'light carmine pink', 'light coral', 'light cornflower blue', 'light crimson', 'light cyan', 'light fuchsia pink', 'light goldenrod yellow', 'light gray', 'light green', 'light khaki', 'light medium orchid', 'light moss green', 'light orchid', 'light pastel purple', 'light pink', 'light red ochre', 'light salmon', 'light salmon pink', 'light sea green', 'light sky blue', 'light slate gray', 'light steel blue', 'light taupe', 'light thulian pink', 'light yellow', 'lilac', 'lime (color wheel)', 'lime (web) (x11 green)', 'lime green', 'limerick', 'lincoln green', 'linen', 'lion', 'little boy blue', 'liver', 'liver (dogs)', 'liver (organ)', 'liver chestnut', 'lumber', 'lust', 'magenta', 'magenta (crayola)', 'magenta (dye)', 'magenta (pantone)', 'magenta (process)', 'magic mint', 'magnolia', 'mahogany', 'maize', 'majorelle blue', 'malachite', 'manatee', 'mango tango', 'mantis', 'mardi gras', 'maroon (crayola)', 'maroon (html/css)', 'maroon (x11)', 'mauve', 'mauve taupe', 'mauvelous', 'maya blue', 'meat brown', 'medium aquamarine', 'medium blue', 'medium candy apple red', 'medium carmine', 'medium champagne', 'medium electric blue', 'medium jungle green', 'medium lavender magenta', 'medium orchid', 'medium persian blue', 'medium purple', 'medium red-violet', 'medium ruby', 'medium sea green', 'medium sky blue', 'medium slate blue', 'medium spring bud', 'medium spring green', 'medium taupe', 'medium turquoise', 'medium tuscan red', 'medium vermilion', 'medium violet-red', 'mellow apricot', 'mellow yellow', 'melon', 'metallic seaweed', 'metallic sunburst', 'mexican pink', 'midnight blue', 'midnight green (eagle green)', 'midori', 'mikado yellow', 'mint', 'mint cream', 'mint green', 'misty rose', 'moccasin', 'mode beige', 'moonstone blue', 'mordant red 19', 'moss green', 'mountain meadow', 'mountbatten pink', 'msu green', 'mughal green', 'mulberry', 'mustard', 'myrtle green', 'sae/ece amber (color)']

&lt;/pre&gt;

&lt;p&gt;
&lt;img src="/media/blues-2.png"&gt; 
&lt;/p&gt;
&lt;p&gt;Copyright (C) 2018 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;
&lt;p&gt;&lt;a href="/org/2013/03/04/Picasso's-short-lived-blue-period-with-Python.org"&gt;org-mode source&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Org-mode version = 9.1.6&lt;/p&gt;]]></content:encoded>
    </item>
  </channel>
</rss>
