<script data-pm-proxy="intercept"></script><?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Hands on Data Visualization, Data Science, AI and Python]]></title><description><![CDATA[Practical tutorials about Data Science, Data Visualization and AI with hands-on coding mostly in Python]]></description><link>https://technofile.substack.com</link><image><url>https://substackcdn.com/image/fetch/$s_!x1nV!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1b92511-34db-46c0-bfed-ad4e6ad27b5e_1024x1024.png</url><title>Hands on Data Visualization, Data Science, AI and Python</title><link>https://technofile.substack.com</link></image><generator>Substack</generator><lastBuildDate>Fri, 04 Sep 2026 20:35:48 GMT</lastBuildDate><atom:link href="/__u/technofile.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Alan Jones]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[technofile@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[technofile@substack.com]]></itunes:email><itunes:name><![CDATA[Alan Jones]]></itunes:name></itunes:owner><itunes:author><![CDATA[Alan Jones]]></itunes:author><googleplay:owner><![CDATA[technofile@substack.com]]></googleplay:owner><googleplay:email><![CDATA[technofile@substack.com]]></googleplay:email><googleplay:author><![CDATA[Alan Jones]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Wide vs Narrow Data: Which You Should Use and Why]]></title><description><![CDATA[Understanding the difference between wide and narrow (long) data formats is essential when plotting with Matplotlib, Seaborn, Plotly Express, and Pandas]]></description><link>https://technofile.substack.com/p/wide-vs-narrow-data-which-you-should</link><guid isPermaLink="false">https://technofile.substack.com/p/wide-vs-narrow-data-which-you-should</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Tue, 21 Jul 2026 18:21:57 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!T8Ac!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3099ce2a-6a51-40cb-8039-d74acb1803f6_1000x563.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!T8Ac!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3099ce2a-6a51-40cb-8039-d74acb1803f6_1000x563.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!T8Ac!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3099ce2a-6a51-40cb-8039-d74acb1803f6_1000x563.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!T8Ac!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3099ce2a-6a51-40cb-8039-d74acb1803f6_1000x563.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!T8Ac!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3099ce2a-6a51-40cb-8039-d74acb1803f6_1000x563.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!T8Ac!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3099ce2a-6a51-40cb-8039-d74acb1803f6_1000x563.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!T8Ac!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3099ce2a-6a51-40cb-8039-d74acb1803f6_1000x563.jpeg" width="1000" height="563" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3099ce2a-6a51-40cb-8039-d74acb1803f6_1000x563.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:563,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!T8Ac!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3099ce2a-6a51-40cb-8039-d74acb1803f6_1000x563.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!T8Ac!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3099ce2a-6a51-40cb-8039-d74acb1803f6_1000x563.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!T8Ac!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3099ce2a-6a51-40cb-8039-d74acb1803f6_1000x563.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!T8Ac!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3099ce2a-6a51-40cb-8039-d74acb1803f6_1000x563.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Photo by Steve A Johnson on Unsplash</figcaption></figure></div><p style="text-align: center;"><em>(This is a complete article, but if you are a Medium member you can also read it <a href="https://medium.com/data-science-collective/wide-vs-narrow-data-which-you-should-use-and-why-b0a713c73956">here</a>)</em></p><p>Most data you come across in publications or on the web is in the human-friendly wide data format; tables in reports, spreadsheets and CSV files are mostly like this. But with plotting tools like Seaborn or Plotly Express and for certain Pandas operations, narrow-format data is more useful or even essential. Different tools need different data formats to work with.</p><p>To be able to use these data formats appropriately, we aim to answer the following questions:</p><ul><li><p>What are narrow and wide data formats?</p></li><li><p>How to plot wide data with Matplotlib and Pandas plots</p></li><li><p>How to convert wide to narrow data with Pandas <code>melt()</code></p></li><li><p>How to plot narrow data with Seaborn and Plotly Express</p></li></ul><h3>Wide Format</h3><p>A <strong>wide</strong> data table is the most familiar. It stores different variables in separate columns. For example, here&#8217;s a summary of monthly fruit sales:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Kcte!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7125dc9d-98fa-49ce-bbcc-b63d2651a55c_269x96.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Kcte!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7125dc9d-98fa-49ce-bbcc-b63d2651a55c_269x96.png 424w, /__u/substackcdn.com/image/fetch/$s_!Kcte!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7125dc9d-98fa-49ce-bbcc-b63d2651a55c_269x96.png 848w, /__u/substackcdn.com/image/fetch/$s_!Kcte!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7125dc9d-98fa-49ce-bbcc-b63d2651a55c_269x96.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Kcte!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7125dc9d-98fa-49ce-bbcc-b63d2651a55c_269x96.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Kcte!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7125dc9d-98fa-49ce-bbcc-b63d2651a55c_269x96.png" width="269" height="96" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7125dc9d-98fa-49ce-bbcc-b63d2651a55c_269x96.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:96,&quot;width&quot;:269,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;A wide data table&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A wide data table" title="A wide data table" srcset="/__u/substackcdn.com/image/fetch/$s_!Kcte!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7125dc9d-98fa-49ce-bbcc-b63d2651a55c_269x96.png 424w, /__u/substackcdn.com/image/fetch/$s_!Kcte!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7125dc9d-98fa-49ce-bbcc-b63d2651a55c_269x96.png 848w, /__u/substackcdn.com/image/fetch/$s_!Kcte!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7125dc9d-98fa-49ce-bbcc-b63d2651a55c_269x96.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Kcte!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7125dc9d-98fa-49ce-bbcc-b63d2651a55c_269x96.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div><p>There is one column for months, each fruit has its own column, and the entry in it represents the number of items sold in that month.</p><p>Spreadsheet users will often organise data this way, and if you are dealing with CSV files, the data is often in this format. It&#8217;s easy to read: focus on the fruit of interest, run your finger down to the right month, and there is the sales figure. We are all used to this sort of thing.</p><h3>Narrow Format</h3><p>Narrow, or long format, is rather different: Instead of one column per fruit, we store the fruit names as values in a single <code>Fruit</code> column. And there is a single <code>Sales</code> column.</p><p>This is not as easy to read as the wide format unless you are Seaborn or Plotly Express!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!VMF_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbeeec777-a059-440a-9415-e928631942ec_188x252.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!VMF_!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbeeec777-a059-440a-9415-e928631942ec_188x252.png 424w, /__u/substackcdn.com/image/fetch/$s_!VMF_!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbeeec777-a059-440a-9415-e928631942ec_188x252.png 848w, /__u/substackcdn.com/image/fetch/$s_!VMF_!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbeeec777-a059-440a-9415-e928631942ec_188x252.png 1272w, /__u/substackcdn.com/image/fetch/$s_!VMF_!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbeeec777-a059-440a-9415-e928631942ec_188x252.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!VMF_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbeeec777-a059-440a-9415-e928631942ec_188x252.png" width="188" height="252" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/beeec777-a059-440a-9415-e928631942ec_188x252.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:252,&quot;width&quot;:188,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;A narrow data table&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A narrow data table" title="A narrow data table" srcset="/__u/substackcdn.com/image/fetch/$s_!VMF_!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbeeec777-a059-440a-9415-e928631942ec_188x252.png 424w, /__u/substackcdn.com/image/fetch/$s_!VMF_!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbeeec777-a059-440a-9415-e928631942ec_188x252.png 848w, /__u/substackcdn.com/image/fetch/$s_!VMF_!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbeeec777-a059-440a-9415-e928631942ec_188x252.png 1272w, /__u/substackcdn.com/image/fetch/$s_!VMF_!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbeeec777-a059-440a-9415-e928631942ec_188x252.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Instead of the fruit types being <strong>column names</strong>, they are now <strong>data values</strong>.</p><h3>Which One Is Better?</h3><p>Neither. Each is better for different tasks.</p><h4>Wide format is best for&#8230;</h4><p>We would typically find wide data in:</p><ul><li><p>spreadsheets</p></li><li><p>reports</p></li><li><p>simple Pandas plots</p></li></ul><p>We&#8217;ll see examples of how to use the different formats with different tools soon. As a sneak preview, below is an example of how easy it is to use wide data with the built-in plotting capabilities of Pandas:</p><pre><code>wide.plot(x=&#8221;Month&#8221;)</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!rqWI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 424w, /__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 848w, /__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 1272w, /__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!rqWI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png" width="552" height="432" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:432,&quot;width&quot;:552,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;A simple plot from Pandas&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A simple plot from Pandas" title="A simple plot from Pandas" srcset="/__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 424w, /__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 848w, /__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 1272w, /__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Pandas automatically plots each numeric column and labels them with the column name. Very convenient.</p><p>Pandas plotting is great for simple, quick plots, but more sophisticated libraries like Seaborn and Plotly have different needs.</p><h4>Long format is best for&#8230;</h4><p>For more sophisticated tools, long format is often preferred, for example in the Seaborn and Plotly Express plotting libraries.</p><p>Indeed, most modern Python visualisation libraries prefer long data, and we will explore these shortly.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/wide-vs-narrow-data-which-you-should?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/wide-vs-narrow-data-which-you-should?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><h3>Creating the DataFrames</h3><p>Before we can demonstrate the usefulness of narrow data, let&#8217;s create the data we saw above.</p><p>Here is the code to create a wide dataframe:</p><pre><code>import pandas as pd

wide = pd.DataFrame({
    &#8220;Month&#8221;:[&#8221;Jan&#8221;,&#8221;Feb&#8221;,&#8221;Mar&#8221;],
    &#8220;Apples&#8221;:[120,150,170],
    &#8220;Oranges&#8221;:[90,95,110],
    &#8220;Bananas&#8221;:[70,65,80]
})</code></pre><p>This will give you the wide table we saw above.</p><p>This is a quick way of creating data to play around with, but in a practical project you are more likely to be importing data from an external source, you might do something like:</p><pre><code>wide = pd.read_csv(&#8221;datapath/fruit_sales.csv)&#8221;)</code></pre><h3>Plotting with Matplotlib</h3><p>The old grandaddy of plotting is comfortable with wide data. Here, plot the individual lines separately.</p><pre><code>import matplotlib.pyplot as plt

plt.plot(wide[&#8221;Month&#8221;], wide[&#8221;Apples&#8221;], label=&#8221;Apples&#8221;)
plt.plot(wide[&#8221;Month&#8221;], wide[&#8221;Oranges&#8221;], label=&#8221;Oranges&#8221;)
plt.plot(wide[&#8221;Month&#8221;], wide[&#8221;Bananas&#8221;], label=&#8221;Bananas&#8221;)
plt.legend()
plt.show()</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!HCi9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ca8dc9-7639-4c5b-bff9-5399b5756ce0_552x413.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!HCi9!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ca8dc9-7639-4c5b-bff9-5399b5756ce0_552x413.png 424w, /__u/substackcdn.com/image/fetch/$s_!HCi9!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ca8dc9-7639-4c5b-bff9-5399b5756ce0_552x413.png 848w, /__u/substackcdn.com/image/fetch/$s_!HCi9!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ca8dc9-7639-4c5b-bff9-5399b5756ce0_552x413.png 1272w, /__u/substackcdn.com/image/fetch/$s_!HCi9!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ca8dc9-7639-4c5b-bff9-5399b5756ce0_552x413.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!HCi9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ca8dc9-7639-4c5b-bff9-5399b5756ce0_552x413.png" width="552" height="413" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e7ca8dc9-7639-4c5b-bff9-5399b5756ce0_552x413.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:413,&quot;width&quot;:552,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;A matplotlib plot&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A matplotlib plot" title="A matplotlib plot" srcset="/__u/substackcdn.com/image/fetch/$s_!HCi9!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ca8dc9-7639-4c5b-bff9-5399b5756ce0_552x413.png 424w, /__u/substackcdn.com/image/fetch/$s_!HCi9!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ca8dc9-7639-4c5b-bff9-5399b5756ce0_552x413.png 848w, /__u/substackcdn.com/image/fetch/$s_!HCi9!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ca8dc9-7639-4c5b-bff9-5399b5756ce0_552x413.png 1272w, /__u/substackcdn.com/image/fetch/$s_!HCi9!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7ca8dc9-7639-4c5b-bff9-5399b5756ce0_552x413.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>A slightly neater method giving the same result using a loop:</p><pre><code>for fruit in [&#8221;Apples&#8221;,&#8221;Oranges&#8221;, &#8220;Bananas&#8221;]:
    plt.plot(wide[&#8221;Month&#8221;], wide[fruit], label=fruit)
plt.legend()
plt.show()</code></pre><p>You have to plot each column individually, and the legend is created by labelling the plots and calling <code>plt.legend()</code>.</p><h3>Plotting with Pandas</h3><p>Using the built-in plotting capabilities of Pandas is very easy with wide format data. If you simply define the x-axis, then Pandas will plot the remaining columns.</p><pre><code>wide.plot(x=&#8221;Month&#8221;)</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!rqWI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 424w, /__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 848w, /__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 1272w, /__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!rqWI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png" width="552" height="432" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:432,&quot;width&quot;:552,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 424w, /__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 848w, /__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 1272w, /__u/substackcdn.com/image/fetch/$s_!rqWI!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa543ff66-872e-46af-9be8-cb6d5878a72e_552x432.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Three lines are plotted automatically: one line per numeric column, and a legend is displayed automatically.</p><p>Pandas plots are based on Matplotlib, but the coding is simpler.</p><h3>Convert Wide to Long</h3><p>It is quite likely you will be provided with wide format data, but converting to narrow format is easily achieved with the Pandas <code>melt()</code> function:</p><pre><code>long = wide.melt(
    id_vars=&#8221;Month&#8221;,
    var_name=&#8221;Fruit&#8221;,
    value_name=&#8221;Sales&#8221;
)</code></pre><p><code>melt()</code> is a very useful Pandas function as it transforms a table from <strong>wide</strong> format (many measurement columns) into <strong>long</strong> format (one measurement column plus a variable column).</p><p>Let&#8217;s go through it step by step.</p><p>In the wide data, there are <strong>four columns</strong>.</p><ul><li><p>Month</p></li><li><p>Apples</p></li><li><p>Oranges</p></li><li><p>Bananas</p></li></ul><p>The <strong>Month</strong> column identifies each row. Imagine that we are going to plot a series of line plots as we did above; <code>Months</code> is on the x-axis, and the values for each fruit column would be plotted against that.</p><p>We want <code>Months</code> to serve the same purpose when we convert it to narrow data, so we want to keep it as it is.</p><p>This is what <code>id_vars</code> means.</p><pre><code>id_vars=&#8221;Month&#8221;</code></pre><p>However, we want to <code>melt</code>all the others. The three columns are going to disappear as columns, and instead, their names become values in a new column.</p><p>We can use <code>melt</code> only specifying the <code>id</code> column like this:</p><pre><code>long = wide.melt(id_vars=&#8221;Month&#8221;)</code></pre><p>The result is this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!YcqG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67e25987-1128-4b5e-8c12-065a45bbbec4_256x402.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!YcqG!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67e25987-1128-4b5e-8c12-065a45bbbec4_256x402.png 424w, /__u/substackcdn.com/image/fetch/$s_!YcqG!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67e25987-1128-4b5e-8c12-065a45bbbec4_256x402.png 848w, /__u/substackcdn.com/image/fetch/$s_!YcqG!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67e25987-1128-4b5e-8c12-065a45bbbec4_256x402.png 1272w, /__u/substackcdn.com/image/fetch/$s_!YcqG!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67e25987-1128-4b5e-8c12-065a45bbbec4_256x402.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!YcqG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67e25987-1128-4b5e-8c12-065a45bbbec4_256x402.png" width="256" height="402" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/67e25987-1128-4b5e-8c12-065a45bbbec4_256x402.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:402,&quot;width&quot;:256,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!YcqG!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67e25987-1128-4b5e-8c12-065a45bbbec4_256x402.png 424w, /__u/substackcdn.com/image/fetch/$s_!YcqG!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67e25987-1128-4b5e-8c12-065a45bbbec4_256x402.png 848w, /__u/substackcdn.com/image/fetch/$s_!YcqG!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67e25987-1128-4b5e-8c12-065a45bbbec4_256x402.png 1272w, /__u/substackcdn.com/image/fetch/$s_!YcqG!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67e25987-1128-4b5e-8c12-065a45bbbec4_256x402.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Two new columns were created automatically: <code>variable</code> and <code>value</code>. These are not very meaningful names, so it&#8217;s better to specify those names ourselves.</p><pre><code>long = wide.melt(id_vars=&#8221;Month&#8221;, var_name=&#8221;Fruit&#8221;, value_name=&#8221;Sales&#8221;)</code></pre><p>This gives a better result:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!jhY9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf5433e7-6051-471d-b7e8-bac9464d5b04_250x414.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!jhY9!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf5433e7-6051-471d-b7e8-bac9464d5b04_250x414.png 424w, /__u/substackcdn.com/image/fetch/$s_!jhY9!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf5433e7-6051-471d-b7e8-bac9464d5b04_250x414.png 848w, /__u/substackcdn.com/image/fetch/$s_!jhY9!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf5433e7-6051-471d-b7e8-bac9464d5b04_250x414.png 1272w, /__u/substackcdn.com/image/fetch/$s_!jhY9!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf5433e7-6051-471d-b7e8-bac9464d5b04_250x414.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!jhY9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf5433e7-6051-471d-b7e8-bac9464d5b04_250x414.png" width="250" height="414" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bf5433e7-6051-471d-b7e8-bac9464d5b04_250x414.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:414,&quot;width&quot;:250,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!jhY9!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf5433e7-6051-471d-b7e8-bac9464d5b04_250x414.png 424w, /__u/substackcdn.com/image/fetch/$s_!jhY9!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf5433e7-6051-471d-b7e8-bac9464d5b04_250x414.png 848w, /__u/substackcdn.com/image/fetch/$s_!jhY9!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf5433e7-6051-471d-b7e8-bac9464d5b04_250x414.png 1272w, /__u/substackcdn.com/image/fetch/$s_!jhY9!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf5433e7-6051-471d-b7e8-bac9464d5b04_250x414.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This table is much easier to understand.</p><p>So let&#8217;s see how we use the long data in a practical setting.</p><h3>Plotting with Seaborn</h3><p>As you may well know, Seaborn is based on Matplotlib but works with long format.</p><pre><code>import seaborn as sns

sns.lineplot(
    data=long,
    x=&#8221;Month&#8221;,
    y=&#8221;Sales&#8221;,
    hue=&#8221;Fruit&#8221;
)</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!23tx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e329e50-8105-4d0c-b415-90f3a3707e68_571x432.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!23tx!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e329e50-8105-4d0c-b415-90f3a3707e68_571x432.png 424w, /__u/substackcdn.com/image/fetch/$s_!23tx!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e329e50-8105-4d0c-b415-90f3a3707e68_571x432.png 848w, /__u/substackcdn.com/image/fetch/$s_!23tx!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e329e50-8105-4d0c-b415-90f3a3707e68_571x432.png 1272w, /__u/substackcdn.com/image/fetch/$s_!23tx!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e329e50-8105-4d0c-b415-90f3a3707e68_571x432.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!23tx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e329e50-8105-4d0c-b415-90f3a3707e68_571x432.png" width="571" height="432" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e329e50-8105-4d0c-b415-90f3a3707e68_571x432.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:432,&quot;width&quot;:571,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!23tx!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e329e50-8105-4d0c-b415-90f3a3707e68_571x432.png 424w, /__u/substackcdn.com/image/fetch/$s_!23tx!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e329e50-8105-4d0c-b415-90f3a3707e68_571x432.png 848w, /__u/substackcdn.com/image/fetch/$s_!23tx!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e329e50-8105-4d0c-b415-90f3a3707e68_571x432.png 1272w, /__u/substackcdn.com/image/fetch/$s_!23tx!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e329e50-8105-4d0c-b415-90f3a3707e68_571x432.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Seaborn plots the sales numbers against the month, and by setting the <code>hue</code> to <code>Fruit</code> understands this as a category, plots a separate line for each and assigns a different colour to each plotted line.</p><p>Consequently, we get one line per fruit, and the legend is automatically generated.</p><h3>Plotting with Plotly Express</h3><p>This is very similar to Seaborn, but instead of the <code>hue</code> parameter we need to set <code>color</code>. (I&#8217;ve set the width here simply to fit the page better.)</p><pre><code>import plotly.express as px

fig = px.line(    
    long,
    x=&#8221;Month&#8221;,
    y=&#8221;Sales&#8221;,
    color=&#8221;Fruit&#8221;,
    width=800
)</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!fMhp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaef0e15-356d-418e-b452-9905b479b82b_800x450.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!fMhp!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaef0e15-356d-418e-b452-9905b479b82b_800x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!fMhp!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaef0e15-356d-418e-b452-9905b479b82b_800x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!fMhp!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaef0e15-356d-418e-b452-9905b479b82b_800x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!fMhp!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaef0e15-356d-418e-b452-9905b479b82b_800x450.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!fMhp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaef0e15-356d-418e-b452-9905b479b82b_800x450.png" width="800" height="450" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/caef0e15-356d-418e-b452-9905b479b82b_800x450.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:450,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!fMhp!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaef0e15-356d-418e-b452-9905b479b82b_800x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!fMhp!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaef0e15-356d-418e-b452-9905b479b82b_800x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!fMhp!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaef0e15-356d-418e-b452-9905b479b82b_800x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!fMhp!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcaef0e15-356d-418e-b452-9905b479b82b_800x450.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>So what&#8217;s good about long data</h3><p>Suppose you add another fruit. With the wide format you would need to add another column so the structure of the data changes. But using long format we just add more rows with a different value for the new fruit.</p><p>This makes little difference to most of the code above. For the Matplotlib version, we would need to add a new line in the Matplotlib code (or a new entry in the list for the loop version), and Pandas plots will pick up a new column automatically.</p><p>The libraries that require narrow data would need no modification at all, as new rows with any data values are catered for automatically.</p><h3>When Should You Use Each?</h3><p>If you are comfortable using Matplotlib or want the simplicity of Pandas plots, then you can use wide data.</p><p>However, if you want to use the sophisticated statistical plots t&#295;at Seaborn offers or the interactivity and flexibility of Plotly Express, then narrow data is pretty much essential.</p><p>When displaying a table, wide data is preferable for human readability, so it&#8217;s a good idea to keep a copy of both forms, narrow for plotting and wide for displaying tables.</p><div><hr></div><p>This has been a very quick and simple look at wide versus long data; there are more sophisticated uses of <code>melt()</code>, Seaborn and Plotly which we might look at another day. Thanks for reading; I hope you have found it useful.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Hands on Data Visualization, Data Science, AI and Python! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/wide-vs-narrow-data-which-you-should?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/wide-vs-narrow-data-which-you-should?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><div><hr></div><h3 style="text-align: center;"><strong><span data-color="#0000ff" style="color: rgb(0, 0, 255);">Curated book titles from Bookshop.org (sponsored links)</span></strong></h3><p style="text-align: center;">Some of the most useful books I&#8217;ve read and can recommend.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://bookshop.org/shop/alanjones&quot;,&quot;text&quot;:&quot;US&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://bookshop.org/shop/alanjones"><span>US</span></a></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://uk.bookshop.org/shop/alanjones&quot;,&quot;text&quot;:&quot;UK&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://uk.bookshop.org/shop/alanjones"><span>UK</span></a></p><p style="text-align: center;"><strong><span data-color="#0000ff" style="color: rgb(0, 0, 255);">Support your local bookshop, not billionaires</span></strong></p><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[MCP vs Function Calling: Which Is Better for AI Agents ]]></title><description><![CDATA[Tools are an AI agent's window to the real world. Without them, the agent would be restricted to what it already knows.]]></description><link>https://technofile.substack.com/p/mcp-vs-function-calling-which-is</link><guid isPermaLink="false">https://technofile.substack.com/p/mcp-vs-function-calling-which-is</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Sat, 30 May 2026 06:50:51 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!fO-D!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3cd0f7f-8e09-4a35-801c-51b567f4bf4f_1000x405.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!fO-D!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3cd0f7f-8e09-4a35-801c-51b567f4bf4f_1000x405.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!fO-D!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3cd0f7f-8e09-4a35-801c-51b567f4bf4f_1000x405.png 424w, /__u/substackcdn.com/image/fetch/$s_!fO-D!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3cd0f7f-8e09-4a35-801c-51b567f4bf4f_1000x405.png 848w, /__u/substackcdn.com/image/fetch/$s_!fO-D!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3cd0f7f-8e09-4a35-801c-51b567f4bf4f_1000x405.png 1272w, /__u/substackcdn.com/image/fetch/$s_!fO-D!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3cd0f7f-8e09-4a35-801c-51b567f4bf4f_1000x405.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!fO-D!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3cd0f7f-8e09-4a35-801c-51b567f4bf4f_1000x405.png" width="1000" height="405" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c3cd0f7f-8e09-4a35-801c-51b567f4bf4f_1000x405.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:405,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!fO-D!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3cd0f7f-8e09-4a35-801c-51b567f4bf4f_1000x405.png 424w, /__u/substackcdn.com/image/fetch/$s_!fO-D!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3cd0f7f-8e09-4a35-801c-51b567f4bf4f_1000x405.png 848w, /__u/substackcdn.com/image/fetch/$s_!fO-D!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3cd0f7f-8e09-4a35-801c-51b567f4bf4f_1000x405.png 1272w, /__u/substackcdn.com/image/fetch/$s_!fO-D!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3cd0f7f-8e09-4a35-801c-51b567f4bf4f_1000x405.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>MCP and Function Calling are both excellent methods of giving an AI Agent access to local or global resources -  essential for most useful applications. We need AI to be able to look at our documents, our calendars, our emails; to trawl the web for information, be it stock movements, travel information or news.</p><p>Without tools, the LLM would be stuck in the world when it was trained, useful, but not useful enough for real-world applications.</p><p>If you&#8217;ve been programming AI agents for a while, then you might well turn to function calling to implement a link to an external source.</p><p>But isn&#8217;t MCP supposed to be the new silver bullet? It seems like the whole world and its dog have implemented an MCP library of tools that lets your agent access their API. So should we follow suit?</p><p>To answer that question, we need to ask a few more questions. But first, let&#8217;s take a quick look at the two technologies&#8230;</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://medium.com/data-science-collective/mcp-vs-function-calling-how-should-your-agent-communicate-with-the-outside-world-8a5e15ec89ac?sk=47c62c38206457b6b25c4e8ee9446c20&quot;,&quot;text&quot;:&quot;Read more for free...&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://medium.com/data-science-collective/mcp-vs-function-calling-how-should-your-agent-communicate-with-the-outside-world-8a5e15ec89ac?sk=47c62c38206457b6b25c4e8ee9446c20"><span>Read more for free...</span></a></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/subscribe"><span>Subscribe now</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Data Analysis with Claude Code and more...]]></title><description><![CDATA[Claude Code is not just for programmers, we see how we can use Claude Code to produce a comprehensive analysis of a data set. Also, how to use Claude Code for free (maybe).]]></description><link>https://technofile.substack.com/p/data-analysis-with-claude-code-and</link><guid isPermaLink="false">https://technofile.substack.com/p/data-analysis-with-claude-code-and</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Sun, 10 May 2026 15:58:46 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ZCKM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec70f07b-0840-4920-a108-f1d961ee8925_1000x707.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!ZCKM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec70f07b-0840-4920-a108-f1d961ee8925_1000x707.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!ZCKM!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec70f07b-0840-4920-a108-f1d961ee8925_1000x707.png 424w, /__u/substackcdn.com/image/fetch/$s_!ZCKM!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec70f07b-0840-4920-a108-f1d961ee8925_1000x707.png 848w, /__u/substackcdn.com/image/fetch/$s_!ZCKM!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec70f07b-0840-4920-a108-f1d961ee8925_1000x707.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ZCKM!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec70f07b-0840-4920-a108-f1d961ee8925_1000x707.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!ZCKM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec70f07b-0840-4920-a108-f1d961ee8925_1000x707.png" width="1000" height="707" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ec70f07b-0840-4920-a108-f1d961ee8925_1000x707.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:707,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!ZCKM!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec70f07b-0840-4920-a108-f1d961ee8925_1000x707.png 424w, /__u/substackcdn.com/image/fetch/$s_!ZCKM!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec70f07b-0840-4920-a108-f1d961ee8925_1000x707.png 848w, /__u/substackcdn.com/image/fetch/$s_!ZCKM!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec70f07b-0840-4920-a108-f1d961ee8925_1000x707.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ZCKM!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fec70f07b-0840-4920-a108-f1d961ee8925_1000x707.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I analysed 78 years of London weather data and produced a comprehensive report with charts, without writing a single line of code. I did this with Claude Code for free.</p><p>So, today, there are links to two articles that you can read on Medium for free that cover the two topics.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/subscribe"><span>Subscribe now</span></a></p><h3><strong>Data Analysis with Claude Code &#8212; it&#8217;s not just for programmers</strong></h3><p>Claude Code has a good reputation as a programmer&#8217;s tool. It can also do a fine job of data analysis.</p><p>I used it to analyse decades of London weather records, got a comprehensive report with detailed charts (like those above) and found real evidence of climate change in London. Claude wrote and executed the code needed to load the data and create the charts, but it all ran in the background &#8212; I didn&#8217;t have to look at the code at all.</p><p>All I had to do was to describe my data, explain what I wanted to know, and Claude Code did the rest &#8212; the analysis, the statistics, the charts, the written report. All of it. The skill it needed from me wasn&#8217;t programming in any conventional sense &#8212; everything I asked was in English.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://medium.com/data-science-collective/data-analysis-with-claude-code-its-not-just-for-programmers-08adb529a70d?sk=e35698bf318fceef66c0e656d8b45ac3&quot;,&quot;text&quot;:&quot;Read for free...&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://medium.com/data-science-collective/data-analysis-with-claude-code-its-not-just-for-programmers-08adb529a70d?sk=e35698bf318fceef66c0e656d8b45ac3"><span>Read for free...</span></a></p><h3><strong>How to Use Claude Code for Free with Ollama</strong></h3><p>Claude Code is a mega-popular vibe-coding environment, and Ollama is a great tool for making LLMs easy to use locally, for free.</p><p>Combining the power of Claude Code with the freedom of Ollama has got to result in something good.</p><p>To run Claude Code conventionally, you need to subscribe to the tune of $20 a month (less if you pay a year up front). Frankly, I don&#8217;t think that&#8217;s anything to complain about, given the productivity gains you could achieve.</p><p>But free is better!</p><p><em>(Since I wrote this article, I have had problems running Claude code - it says a subscription is needed. This is not true, but it may be that Ollama restricts access for certain models at certain times, and it is translated as an error. Using a different model might work better - I have not yet had time to get to the bottom of the problem.</em>)</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://medium.com/@alan-jones/how-to-use-claude-code-for-free-a9b0138eb9d1?sk=4b3dff681718a35d6384351cd89c5a2f&quot;,&quot;text&quot;:&quot;Read for free...&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://medium.com/@alan-jones/how-to-use-claude-code-for-free-a9b0138eb9d1?sk=4b3dff681718a35d6384351cd89c5a2f"><span>Read for free...</span></a></p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!s2Qt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9313b492-a6b6-4a6f-91cd-241a5268cddd_2048x600.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!s2Qt!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9313b492-a6b6-4a6f-91cd-241a5268cddd_2048x600.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!s2Qt!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9313b492-a6b6-4a6f-91cd-241a5268cddd_2048x600.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!s2Qt!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9313b492-a6b6-4a6f-91cd-241a5268cddd_2048x600.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!s2Qt!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9313b492-a6b6-4a6f-91cd-241a5268cddd_2048x600.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!s2Qt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9313b492-a6b6-4a6f-91cd-241a5268cddd_2048x600.jpeg" width="1456" height="427" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9313b492-a6b6-4a6f-91cd-241a5268cddd_2048x600.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:427,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:69635,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://technofile.substack.com/i/197114677?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9313b492-a6b6-4a6f-91cd-241a5268cddd_2048x600.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!s2Qt!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9313b492-a6b6-4a6f-91cd-241a5268cddd_2048x600.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!s2Qt!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9313b492-a6b6-4a6f-91cd-241a5268cddd_2048x600.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!s2Qt!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9313b492-a6b6-4a6f-91cd-241a5268cddd_2048x600.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!s2Qt!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9313b492-a6b6-4a6f-91cd-241a5268cddd_2048x600.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4><strong>See my curated list of Data Visualization books on Bookshop.org <a href="https://bookshop.org/shop/alanjones">US</a> <a href="https://bookshop.co.uk/shop/alanjones">UK</a></strong></h4>]]></content:encoded></item><item><title><![CDATA[Why Do Matplotlib Charts Look Bad — and how to fix them]]></title><description><![CDATA[Improve the look of your Matplotlib charts with just a few lines of code]]></description><link>https://technofile.substack.com/p/why-do-matplotlib-charts-look-bad</link><guid isPermaLink="false">https://technofile.substack.com/p/why-do-matplotlib-charts-look-bad</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Mon, 27 Apr 2026 07:32:55 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!G_xb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F305ae21e-9857-4007-b75d-853f60b95918_700x434.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!G_xb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F305ae21e-9857-4007-b75d-853f60b95918_700x434.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!G_xb!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F305ae21e-9857-4007-b75d-853f60b95918_700x434.png 424w, /__u/substackcdn.com/image/fetch/$s_!G_xb!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F305ae21e-9857-4007-b75d-853f60b95918_700x434.png 848w, /__u/substackcdn.com/image/fetch/$s_!G_xb!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F305ae21e-9857-4007-b75d-853f60b95918_700x434.png 1272w, /__u/substackcdn.com/image/fetch/$s_!G_xb!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F305ae21e-9857-4007-b75d-853f60b95918_700x434.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!G_xb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F305ae21e-9857-4007-b75d-853f60b95918_700x434.png" width="700" height="434" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/305ae21e-9857-4007-b75d-853f60b95918_700x434.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:434,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!G_xb!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F305ae21e-9857-4007-b75d-853f60b95918_700x434.png 424w, /__u/substackcdn.com/image/fetch/$s_!G_xb!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F305ae21e-9857-4007-b75d-853f60b95918_700x434.png 848w, /__u/substackcdn.com/image/fetch/$s_!G_xb!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F305ae21e-9857-4007-b75d-853f60b95918_700x434.png 1272w, /__u/substackcdn.com/image/fetch/$s_!G_xb!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F305ae21e-9857-4007-b75d-853f60b95918_700x434.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Matplotlib has been a mainstay of data visualisation for decades &#8212; it is a powerful package. But because it&#8217;s been with us for a long time and it is rooted in visualisation for print media, its default style can produce charts that look like relics from 20 years ago.</p><p>More modern styles use less &#8216;ink&#8217; and are not afraid of white space. They also tend to use fewer primary colours and are generally more subtle.</p><p>There are stylesheets that will give Matplotlib a more modern look, and they are easy to use, but we are going to look at how we can, step by step, with a little thought and a few lines of code, very simply bring a more modern look to our classically styled charts.</p><p>We will also show how we can translate that code into an easily used custom stylesheet.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://medium.com/codefile/why-do-matplotlib-charts-look-bad-and-what-to-do-about-it-51d99f94b8a4?sk=aea85c0c8664bb3a69d2e6716f717109&quot;,&quot;text&quot;:&quot;Continue to read for free...&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://medium.com/codefile/why-do-matplotlib-charts-look-bad-and-what-to-do-about-it-51d99f94b8a4?sk=aea85c0c8664bb3a69d2e6716f717109"><span>Continue to read for free...</span></a></p><p><em>This is an occasional newsletter that links to articles about Data Vizualisation and AI. My articles are usually published on Medium, and the links here will be to a free version.</em></p><p><em>You can follow me on Medium <a href="https://medium.com/@alan-jones">here</a></em></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[A Pause...]]></title><description><![CDATA[A domestic situation prevents me from spending much time on this Substack, so my posts will be even more erratic than usual.]]></description><link>https://technofile.substack.com/p/a-pause</link><guid isPermaLink="false">https://technofile.substack.com/p/a-pause</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Sat, 07 Feb 2026 15:11:04 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!x1nV!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1b92511-34db-46c0-bfed-ad4e6ad27b5e_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A domestic situation prevents me from spending much time on this Substack, so my posts will be even more erratic than usual. Indeed, I may not be able to post anything new for the time being.</p><p>So, if you are a paid subscriber, please <strong>cancel your payment</strong> and subscribe for free instead. </p><p>If you are a free subscriber, then please don&#8217;t cancel your subscription - I hope to get back to posting in the future. </p>]]></content:encoded></item><item><title><![CDATA[Plotly Studio: AI Data Analysis and Visualization]]></title><description><![CDATA[Plotly Studio is a clever and polished product that makes data analysis and visualization a breeze]]></description><link>https://technofile.substack.com/p/plotly-studio-ai-data-analysis-and</link><guid isPermaLink="false">https://technofile.substack.com/p/plotly-studio-ai-data-analysis-and</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Wed, 28 Jan 2026 15:58:24 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!qNzb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbedafb1a-90ce-4768-b900-0bd6fe4ad19d_1100x645.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!qNzb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbedafb1a-90ce-4768-b900-0bd6fe4ad19d_1100x645.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!qNzb!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbedafb1a-90ce-4768-b900-0bd6fe4ad19d_1100x645.png 424w, /__u/substackcdn.com/image/fetch/$s_!qNzb!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbedafb1a-90ce-4768-b900-0bd6fe4ad19d_1100x645.png 848w, /__u/substackcdn.com/image/fetch/$s_!qNzb!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbedafb1a-90ce-4768-b900-0bd6fe4ad19d_1100x645.png 1272w, /__u/substackcdn.com/image/fetch/$s_!qNzb!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbedafb1a-90ce-4768-b900-0bd6fe4ad19d_1100x645.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!qNzb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbedafb1a-90ce-4768-b900-0bd6fe4ad19d_1100x645.png" width="1100" height="645" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bedafb1a-90ce-4768-b900-0bd6fe4ad19d_1100x645.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:645,&quot;width&quot;:1100,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!qNzb!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbedafb1a-90ce-4768-b900-0bd6fe4ad19d_1100x645.png 424w, /__u/substackcdn.com/image/fetch/$s_!qNzb!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbedafb1a-90ce-4768-b900-0bd6fe4ad19d_1100x645.png 848w, /__u/substackcdn.com/image/fetch/$s_!qNzb!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbedafb1a-90ce-4768-b900-0bd6fe4ad19d_1100x645.png 1272w, /__u/substackcdn.com/image/fetch/$s_!qNzb!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbedafb1a-90ce-4768-b900-0bd6fe4ad19d_1100x645.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You might have seen AI-driven data visualization applications before, but other tools that I have used have a kind of DIY feel. </p><p>By contrast, Plotly Studio is a complete desktop app that takes you smoothly and professionally from raw data to a visualization application.</p><p>I have written about how to use AI for data analysis and visualisation using <a href="https://medium.com/ai-advances/data-analysis-and-visualization-with-gemini-and-google-colab-df29f32d3fd5">Google Colab&#8217;s Data Science Agent</a> and also using <a href="https://medium.com/data-science-collective/one-command-to-turn-any-csv-into-a-streamlit-app-with-gemini-cli-5ce43804a9cf">Gemini CLI</a>. Plotly Studio has similar aims, but it is quite a different beast. Whereas the other approaches are extensions of a general-purpose tool, Plotly Studio is a desktop app dedicated to transforming data into data visualisation implemented in Dash.</p><p>Plotly Studio is a recent product from Plotly that is being heavily promoted, but unlike the Plotly chart library, it is not free. This is unsurprising as it incorporates a significant AI element that does not rely on the user&#8217;s own subscriptions. However, there is a range of reasonable pricing options, including a free one that lets you get a feel of the product&#8230;</p><p>Continue reading the full article for free <a href="https://medium.com/codefile/plotly-studio-ai-data-analysis-and-visualization-5f5dfe42775f?sk=7edcebd13095a1df3c13058f6c7c4d31">here</a>.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/subscribe"><span>Subscribe now</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Pandas Plots: Matplotlib Made Easy]]></title><description><![CDATA[Matplotlib is a powerful charting library; Pandas plots are the same, but simpler.]]></description><link>https://technofile.substack.com/p/pandas-plots-matplotlib-made-easy</link><guid isPermaLink="false">https://technofile.substack.com/p/pandas-plots-matplotlib-made-easy</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Fri, 14 Nov 2025 15:56:51 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!sOeB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa245e064-0e2f-4589-b2a8-82f5962d367a_1100x733.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!sOeB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa245e064-0e2f-4589-b2a8-82f5962d367a_1100x733.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!sOeB!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa245e064-0e2f-4589-b2a8-82f5962d367a_1100x733.png 424w, /__u/substackcdn.com/image/fetch/$s_!sOeB!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa245e064-0e2f-4589-b2a8-82f5962d367a_1100x733.png 848w, /__u/substackcdn.com/image/fetch/$s_!sOeB!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa245e064-0e2f-4589-b2a8-82f5962d367a_1100x733.png 1272w, /__u/substackcdn.com/image/fetch/$s_!sOeB!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa245e064-0e2f-4589-b2a8-82f5962d367a_1100x733.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!sOeB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa245e064-0e2f-4589-b2a8-82f5962d367a_1100x733.png" width="1100" height="733" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a245e064-0e2f-4589-b2a8-82f5962d367a_1100x733.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:733,&quot;width&quot;:1100,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!sOeB!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa245e064-0e2f-4589-b2a8-82f5962d367a_1100x733.png 424w, /__u/substackcdn.com/image/fetch/$s_!sOeB!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa245e064-0e2f-4589-b2a8-82f5962d367a_1100x733.png 848w, /__u/substackcdn.com/image/fetch/$s_!sOeB!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa245e064-0e2f-4589-b2a8-82f5962d367a_1100x733.png 1272w, /__u/substackcdn.com/image/fetch/$s_!sOeB!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa245e064-0e2f-4589-b2a8-82f5962d367a_1100x733.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Matplotlib is powerful but can be daunting as it can get verbose when you move beyond basic charts. If you don&#8217;t need that level of granular control, there&#8217;s a faster path to great visuals: the built-in plotting tools in Pandas. They deliver clean, effective charts with a fraction of the code, letting you focus on insights instead of syntax.</strong></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands on Data Visualization, Data Science, AI and Python is a free publication. To receive new posts and support my work, consider becoming a subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>As you might expect, the Pandas plotting library is designed to plot data provided as Pandas dataframes; indeed, the plotting methods are methods from the <code>dataframe</code> class. In the examples below, we will use a dataframe named <code>weather </code>that records the weather in London in the year 2024. To draw a simple line chart of the maximum monthly temperatures, you would write the code below:</p><pre><code>weather.plot(x=&#8217;Month&#8217;, y=&#8217;Tmax&#8217;)</code></pre><p>This is about as simple as it gets. Unless we specify otherwise, the default plot is a line chart. In the code, the <code>plot</code> method from <code>weather</code> is given values for the <code>y</code> and <code>x</code> parameters and will draw the appropriate line chart.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!ZpYq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb19967f7-2df6-4bbc-a207-606312bd6add_538x390.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!ZpYq!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb19967f7-2df6-4bbc-a207-606312bd6add_538x390.png 424w, /__u/substackcdn.com/image/fetch/$s_!ZpYq!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb19967f7-2df6-4bbc-a207-606312bd6add_538x390.png 848w, /__u/substackcdn.com/image/fetch/$s_!ZpYq!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb19967f7-2df6-4bbc-a207-606312bd6add_538x390.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ZpYq!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb19967f7-2df6-4bbc-a207-606312bd6add_538x390.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!ZpYq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb19967f7-2df6-4bbc-a207-606312bd6add_538x390.png" width="538" height="390" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b19967f7-2df6-4bbc-a207-606312bd6add_538x390.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:390,&quot;width&quot;:538,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!ZpYq!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb19967f7-2df6-4bbc-a207-606312bd6add_538x390.png 424w, /__u/substackcdn.com/image/fetch/$s_!ZpYq!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb19967f7-2df6-4bbc-a207-606312bd6add_538x390.png 848w, /__u/substackcdn.com/image/fetch/$s_!ZpYq!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb19967f7-2df6-4bbc-a207-606312bd6add_538x390.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ZpYq!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb19967f7-2df6-4bbc-a207-606312bd6add_538x390.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>The rest of this article covers the basic charts available from Pandas; future articles will look at statistical charts and customisation.</em></p><p><em><strong>Carry on reading for free <a href="https://medium.com/codefile/pandas-plots-matplotlib-made-easy-6b04371552c6?sk=d25060eded893404acf36d59558525d5">here&#8230;</a></strong></em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/pandas-plots-matplotlib-made-easy?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/pandas-plots-matplotlib-made-easy?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Matplotlib or Plotly: how to choose the right Python visualization library]]></title><description><![CDATA[Should you use an interactive Python library like Plotly or a static one like Matplotlib &#8212; it depends on what type of visualization you need.]]></description><link>https://technofile.substack.com/p/matplotlib-or-plotly-how-to-choose</link><guid isPermaLink="false">https://technofile.substack.com/p/matplotlib-or-plotly-how-to-choose</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Thu, 23 Oct 2025 16:20:42 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!r_KP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9abd2f-c5ae-481c-91a9-e7416ca0a2ae_1100x734.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!r_KP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9abd2f-c5ae-481c-91a9-e7416ca0a2ae_1100x734.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!r_KP!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9abd2f-c5ae-481c-91a9-e7416ca0a2ae_1100x734.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!r_KP!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9abd2f-c5ae-481c-91a9-e7416ca0a2ae_1100x734.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!r_KP!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9abd2f-c5ae-481c-91a9-e7416ca0a2ae_1100x734.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!r_KP!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9abd2f-c5ae-481c-91a9-e7416ca0a2ae_1100x734.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!r_KP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9abd2f-c5ae-481c-91a9-e7416ca0a2ae_1100x734.jpeg" width="1100" height="734" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cd9abd2f-c5ae-481c-91a9-e7416ca0a2ae_1100x734.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:734,&quot;width&quot;:1100,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!r_KP!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9abd2f-c5ae-481c-91a9-e7416ca0a2ae_1100x734.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!r_KP!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9abd2f-c5ae-481c-91a9-e7416ca0a2ae_1100x734.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!r_KP!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9abd2f-c5ae-481c-91a9-e7416ca0a2ae_1100x734.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!r_KP!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd9abd2f-c5ae-481c-91a9-e7416ca0a2ae_1100x734.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Photo by <a href="https://unsplash.com/@jakubzerdzicki?utm_source=medium&amp;utm_medium=referral">Jakub &#379;erdzicki</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure></div><p>Matplotlib and Plotly are both data visualization powerhouses, but they were created for different purposes. Which you use depends on the purpose of your Python application.</p><p>Matplotlib was created back in the early 2000s and is a very flexible, low-level library for creating high-quality, print-ready, static plots.</p><p>Plotly, on the other hand, is newer and was built to be interactive and for the web.</p><p>Plotly uses its own <em>plotly.js</em> JavaScript library to render plots &#8212; a Python application produces a JSON specification, which is passed to the JavaScript library to be rendered. Whereas Matplotlib uses different backends depending on the output format required.</p><p>So, while there is overlap between the two libraries (you can display Matplotlib figures in a webpage, and you can download Plotly figures as static printable charts), they are different beasts and built for different purposes.</p><p>To help you choose the right solution, we&#8217;ll look at three aspects of the libraries: interactivity, style and ease of use.</p><h4>Continue reading the full article for free <a href="https://medium.com/codefile/matplotlib-or-plotly-how-to-choose-the-right-python-visualization-library-185200f236dd?sk=76f5e9b1146e3880eeeeaf5ee9e61d0f">here</a></h4><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">To get more free articles subscribe to Data Visualization, Data Science, AI and Python.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[px_xtras: Beyond Plotly Express, More Beautiful Charts]]></title><description><![CDATA[What do Waffle, Waterfall and Dumbbell charts have in common? They&#8217;re not in Plotly Express &#8212; px_xtras to the rescue!]]></description><link>https://technofile.substack.com/p/px_xtras-beyond-plotly-express-more</link><guid isPermaLink="false">https://technofile.substack.com/p/px_xtras-beyond-plotly-express-more</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Wed, 08 Oct 2025 16:15:18 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!yqtq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d4c963f-1f16-4cb6-b6e6-5869f78c3088_1000x750.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!yqtq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d4c963f-1f16-4cb6-b6e6-5869f78c3088_1000x750.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!yqtq!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d4c963f-1f16-4cb6-b6e6-5869f78c3088_1000x750.png 424w, /__u/substackcdn.com/image/fetch/$s_!yqtq!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d4c963f-1f16-4cb6-b6e6-5869f78c3088_1000x750.png 848w, /__u/substackcdn.com/image/fetch/$s_!yqtq!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d4c963f-1f16-4cb6-b6e6-5869f78c3088_1000x750.png 1272w, /__u/substackcdn.com/image/fetch/$s_!yqtq!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d4c963f-1f16-4cb6-b6e6-5869f78c3088_1000x750.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!yqtq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d4c963f-1f16-4cb6-b6e6-5869f78c3088_1000x750.png" width="1000" height="750" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d4c963f-1f16-4cb6-b6e6-5869f78c3088_1000x750.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:750,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!yqtq!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d4c963f-1f16-4cb6-b6e6-5869f78c3088_1000x750.png 424w, /__u/substackcdn.com/image/fetch/$s_!yqtq!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d4c963f-1f16-4cb6-b6e6-5869f78c3088_1000x750.png 848w, /__u/substackcdn.com/image/fetch/$s_!yqtq!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d4c963f-1f16-4cb6-b6e6-5869f78c3088_1000x750.png 1272w, /__u/substackcdn.com/image/fetch/$s_!yqtq!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d4c963f-1f16-4cb6-b6e6-5869f78c3088_1000x750.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Of course, you&#8217;ve used <a href="https://plotly.com/python/plotly-express/">Plotly Express</a> to create quick and beautiful charts, and you know how easy it makes data visualisation in Python. But if your needs grow beyond the standard offerings, you might find yourself tangled up in complex Plotly Graph Objects (GO) code.</p><p>That&#8217;s where <code>px_xtras</code> comes in.</p><h2><strong>What is </strong><code>px_xtras</code><strong>?</strong></h2><p><code>px_xtras</code> is a Python library that mimics the simplicity of Plotly Express to hide the complexity of Plotly GO. It offers a clean, high-level interface to create new visualisations with just a few lines of code.</p><p>And, of course, it plays nicely with popular frameworks like Streamlit or Taipy and anywhere else you can use Plotly charts.</p><p>The current range of charts includes:</p><ul><li><p>Waterfall charts</p></li><li><p>Waffle charts</p></li><li><p>Dumbbell charts</p></li><li><p>Lollipop charts</p></li><li><p>Slope charts</p></li><li><p>Metric &#8212; a text-based visualisation of changing data</p></li></ul><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/subscribe"><span>Subscribe now</span></a></p><p>Here is an example of the code for a Waterfall Chart:</p><p><code># Waterfall Chart<br>wf_data = pd.DataFrame({<br> &#8220;Category&#8221;: [&#8221;Revenue&#8221;, &#8220;COGS&#8221;, &#8220;Operating Expenses&#8221;, &#8220;Taxes&#8221;, &#8220;Net Profit&#8221;],<br> &#8220;Value&#8221;: [100000, -50000, -20000, -10000, 0],<br>})<br>fig_wf = pxx.waterfall(df=wf_data, <br> categories_col=&#8217;Category&#8217;,<br> values_col=&#8217;Value&#8217;,<br> title=&#8221;Company Profit Waterfall&#8221;,<br> )<br>st.plotly_chart(fig_wf</code>)</p><p></p><p>And here is the result:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!YERr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80351be0-0d4d-43b1-aa6e-7426a1442df8_700x447.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!YERr!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80351be0-0d4d-43b1-aa6e-7426a1442df8_700x447.png 424w, /__u/substackcdn.com/image/fetch/$s_!YERr!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80351be0-0d4d-43b1-aa6e-7426a1442df8_700x447.png 848w, /__u/substackcdn.com/image/fetch/$s_!YERr!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80351be0-0d4d-43b1-aa6e-7426a1442df8_700x447.png 1272w, /__u/substackcdn.com/image/fetch/$s_!YERr!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80351be0-0d4d-43b1-aa6e-7426a1442df8_700x447.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!YERr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80351be0-0d4d-43b1-aa6e-7426a1442df8_700x447.png" width="700" height="447" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/80351be0-0d4d-43b1-aa6e-7426a1442df8_700x447.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:447,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!YERr!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80351be0-0d4d-43b1-aa6e-7426a1442df8_700x447.png 424w, /__u/substackcdn.com/image/fetch/$s_!YERr!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80351be0-0d4d-43b1-aa6e-7426a1442df8_700x447.png 848w, /__u/substackcdn.com/image/fetch/$s_!YERr!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80351be0-0d4d-43b1-aa6e-7426a1442df8_700x447.png 1272w, /__u/substackcdn.com/image/fetch/$s_!YERr!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F80351be0-0d4d-43b1-aa6e-7426a1442df8_700x447.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You can read the full article here:</p><h1><code>px_xtras: </code><strong><a href="https://medium.com/data-science-collective/px-xtras-beyond-plotly-express-more-beautiful-charts-eb5882e7654a?sk=6d3c9e31d2ce29a6b4425d2b291ff4a5">Beyond Plotly Express, More Beautiful Charts</a></strong></h1><p>(Medium - no paywall)</p><p>And here are some more example charts:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!-xPm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3afdedf9-cb88-4c52-b9e7-242d928e92b8_700x474.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!-xPm!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3afdedf9-cb88-4c52-b9e7-242d928e92b8_700x474.png 424w, /__u/substackcdn.com/image/fetch/$s_!-xPm!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3afdedf9-cb88-4c52-b9e7-242d928e92b8_700x474.png 848w, /__u/substackcdn.com/image/fetch/$s_!-xPm!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3afdedf9-cb88-4c52-b9e7-242d928e92b8_700x474.png 1272w, /__u/substackcdn.com/image/fetch/$s_!-xPm!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3afdedf9-cb88-4c52-b9e7-242d928e92b8_700x474.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!-xPm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3afdedf9-cb88-4c52-b9e7-242d928e92b8_700x474.png" width="700" height="474" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3afdedf9-cb88-4c52-b9e7-242d928e92b8_700x474.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:474,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!-xPm!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3afdedf9-cb88-4c52-b9e7-242d928e92b8_700x474.png 424w, /__u/substackcdn.com/image/fetch/$s_!-xPm!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3afdedf9-cb88-4c52-b9e7-242d928e92b8_700x474.png 848w, /__u/substackcdn.com/image/fetch/$s_!-xPm!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3afdedf9-cb88-4c52-b9e7-242d928e92b8_700x474.png 1272w, /__u/substackcdn.com/image/fetch/$s_!-xPm!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3afdedf9-cb88-4c52-b9e7-242d928e92b8_700x474.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/px_xtras-beyond-plotly-express-more?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/px_xtras-beyond-plotly-express-more?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p>]]></content:encoded></item><item><title><![CDATA[Vibe Analysis: Conversational Data Exploration with Streamlit and LLMs]]></title><description><![CDATA[How to summon up a customised data dashboard from your data in plain English.]]></description><link>https://technofile.substack.com/p/vibe-analysis-conversational-data</link><guid isPermaLink="false">https://technofile.substack.com/p/vibe-analysis-conversational-data</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Sat, 20 Sep 2025 15:41:24 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!eeIH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc66e42d1-1eb0-42a2-8599-34c10548c7ab_1100x733.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!eeIH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc66e42d1-1eb0-42a2-8599-34c10548c7ab_1100x733.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!eeIH!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc66e42d1-1eb0-42a2-8599-34c10548c7ab_1100x733.png 424w, /__u/substackcdn.com/image/fetch/$s_!eeIH!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc66e42d1-1eb0-42a2-8599-34c10548c7ab_1100x733.png 848w, /__u/substackcdn.com/image/fetch/$s_!eeIH!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc66e42d1-1eb0-42a2-8599-34c10548c7ab_1100x733.png 1272w, /__u/substackcdn.com/image/fetch/$s_!eeIH!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc66e42d1-1eb0-42a2-8599-34c10548c7ab_1100x733.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!eeIH!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc66e42d1-1eb0-42a2-8599-34c10548c7ab_1100x733.png" width="1200" height="799.6363636363636" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c66e42d1-1eb0-42a2-8599-34c10548c7ab_1100x733.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:733,&quot;width&quot;:1100,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:&quot;center&quot;,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!eeIH!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc66e42d1-1eb0-42a2-8599-34c10548c7ab_1100x733.png 424w, /__u/substackcdn.com/image/fetch/$s_!eeIH!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc66e42d1-1eb0-42a2-8599-34c10548c7ab_1100x733.png 848w, /__u/substackcdn.com/image/fetch/$s_!eeIH!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc66e42d1-1eb0-42a2-8599-34c10548c7ab_1100x733.png 1272w, /__u/substackcdn.com/image/fetch/$s_!eeIH!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc66e42d1-1eb0-42a2-8599-34c10548c7ab_1100x733.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You have a new data set, a CSV file, so you spin up a Jupyter Notebook, import <em>pandas</em>, <em>numpy</em>, <em>matplotlib</em>, whatever&#8230; create a dataframe and start wrangling the data, building pretty much the same old charts that you made last time.</p><p>It&#8217;s fine, it works, you&#8217;ve done it all before. It&#8217;s not difficult, but isn&#8217;t it just a bit&#8230; tedious?</p><p>How about a different approach? How about, like the guy in the pointy hat above, you command the visualisations to appear, and they obediently do so?</p><div><hr></div><p>I&#8217;ve been experimenting with the Gemini CLI for data analysis and the automatic production of interactive Streamlit dashboards from that data.</p><p>The following non-paywalled articles show my approach&#8230;</p><h3><strong><a href="https://medium.com/ai-advances/vibe-analysis-conversational-data-exploration-with-streamlit-and-llms-200a2e6e2b41?sk=f19814a88b9bcf9bb8ef51e7b3f832ad">Vibe Analysis: Conversational Data Exploration with Streamlit and LLMs</a></strong></h3><p></p><h3><strong><a href="https://medium.com/data-science-collective/one-command-to-turn-any-csv-into-a-streamlit-app-with-gemini-cli-5ce43804a9cf?sk=6e18afc13e9f0e328a60b152b095db2b">One Command to Turn Any CSV into a Streamlit App with Gemini CLI</a></strong></h3><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/subscribe"><span>Subscribe now</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[I created a Streamlit Dashboard in less than 5 Minutes with Gemini CLI]]></title><description><![CDATA[Combining the two topics of this Substack, I created a Streamlit dashboard with AI.]]></description><link>https://technofile.substack.com/p/i-created-a-streamlit-dashboard-in</link><guid isPermaLink="false">https://technofile.substack.com/p/i-created-a-streamlit-dashboard-in</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Thu, 07 Aug 2025 11:03:46 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!sZ7I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875c8589-17a9-4998-a344-4615c1e3ed51_1000x439.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Combining the two topics of this Substack, I created a Streamlit dashboard with AI. Here&#8217;s a screenshot:</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!sZ7I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875c8589-17a9-4998-a344-4615c1e3ed51_1000x439.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!sZ7I!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875c8589-17a9-4998-a344-4615c1e3ed51_1000x439.png 424w, /__u/substackcdn.com/image/fetch/$s_!sZ7I!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875c8589-17a9-4998-a344-4615c1e3ed51_1000x439.png 848w, /__u/substackcdn.com/image/fetch/$s_!sZ7I!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875c8589-17a9-4998-a344-4615c1e3ed51_1000x439.png 1272w, /__u/substackcdn.com/image/fetch/$s_!sZ7I!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875c8589-17a9-4998-a344-4615c1e3ed51_1000x439.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!sZ7I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875c8589-17a9-4998-a344-4615c1e3ed51_1000x439.png" width="1000" height="439" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/875c8589-17a9-4998-a344-4615c1e3ed51_1000x439.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:439,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!sZ7I!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875c8589-17a9-4998-a344-4615c1e3ed51_1000x439.png 424w, /__u/substackcdn.com/image/fetch/$s_!sZ7I!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875c8589-17a9-4998-a344-4615c1e3ed51_1000x439.png 848w, /__u/substackcdn.com/image/fetch/$s_!sZ7I!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875c8589-17a9-4998-a344-4615c1e3ed51_1000x439.png 1272w, /__u/substackcdn.com/image/fetch/$s_!sZ7I!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F875c8589-17a9-4998-a344-4615c1e3ed51_1000x439.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This was a remarkably quick and easy way to create data visualisations directly from the data. You can read the full story here (No paywall):</p><h2><strong><a href="https://medium.com/codefile/i-created-a-documented-streamlit-dashboard-in-less-than-5-minutes-with-gemini-cli-b2b64ecc4bcb?sk=bd234cf392de492739310e168be7302f">I created a documented Streamlit Dashboard in less than 5 Minutes with Gemini CLI</a></strong></h2><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/i-created-a-streamlit-dashboard-in?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/i-created-a-streamlit-dashboard-in?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><p>Apart from my own work, I&#8217;ve been reading some interesting articles in Data Science and AI. Here are a couple that are definitely worth your time.</p><h2>Agents aren&#8217;t always the solution</h2><p>While reviewing my own recent offering, <strong><a href="https://towardsdatascience.com/build-multi-agent-apps-with-openais-agent-sdk/">Build Multi-Agent Apps with OpenAI&#8217;s Agent </a></strong><a href="https://towardsdatascience.com/build-multi-agent-apps-with-openais-agent-sdk/">SDK</a>, I came across a very interesting take on the use of AI agents, or indeed, when not to use them. </p><p><strong><a href="https://towardsdatascience.com/a-developers-guide-to-building-scalable-ai-workflows-vs-agents/">A Developer&#8217;s Guide to Building Scalable AI: Workflows vs Agents</a></strong> shows how a workflow model that uses direct calls to an LLM is often more appropriate than an agentic approach. It does a good job of explaining the pros and cons of the agentic apps and, is a warning that, even if they are fun and sexy, you shouldn&#8217;t just grab at the next shiny thing but think a bit more deeply about the nature of your project before diving in. If you are thinking of getting involved in AI app development, this is well worth a read. </p><p>A shorter and equally authoritative piece from Anthropic, <strong><a href="https://www.anthropic.com/engineering/building-effective-agents">Building effective agents</a>,</strong> also sets out the difference between workflow-based apps and those using agents.</p><p></p><h2>Data Visualization with ChatGPT</h2><p><span class="mention-wrap" data-attrs="{&quot;name&quot;:&quot;John Loewen&quot;,&quot;id&quot;:112302149,&quot;type&quot;:&quot;user&quot;,&quot;url&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/adb9eed0-3223-4003-9f98-d0c6907b20bd_1074x1162.png&quot;,&quot;uuid&quot;:&quot;1956b08c-99e9-4fc8-bbcc-9e1ad32c4838&quot;}" data-component-name="MentionToDOM"></span> is excellent in finding interesting data and presenting it in novel ways. His recent Substack,<strong> <a href="/__u/johnloewen.substack.com/p/is-gpt-4o-now-any-better-with-data">Is GPT-4o Now Any Better With Data Visualization Report Creation?</a> </strong>explores how to use ChatGPT to create PDF reports which include automatically generated charts. His starting point is the Harvard Comparative Death Penalty Database and, as he says, &#8220;Bringing death penalty data to life shows us where the world stands on one of the most controversial practices in the legal system.&#8221; And he does this by walking us through how to use GPT-4o to analyse the data, produce data visualization and produce a complete report in PDF format.</p><p></p><p>All links are to free articles unless otherwise indicated with a $ after the title.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/subscribe"><span>Subscribe now</span></a></p><h3>Support your local bookshop, not billionaires</h3><p>I&#8217;ve created a set of recommended books, mainly about data visualization. They are available on my shopfront on <em><strong>bookshop.org</strong></em>.  Books can be delivered from a real shop of your choice. I have a shopfront in the <strong><a href="http://Bringing death penalty data to life shows us where the world stands on one of the most controversial practices in the legal system.">US</a></strong> and the <strong><a href="https://uk.bookshop.org/shop/alanjones">UK</a></strong>. Purchases generate a small commission for me.</p>]]></content:encoded></item><item><title><![CDATA[Build Multi-Agent Apps with OpenAI’s Agent SDK]]></title><description><![CDATA[Creating multi-agent apps is simple with this open-source SDK, and it can be used with any OpenAI-compatible LLM.]]></description><link>https://technofile.substack.com/p/build-multi-agent-apps-with-openais</link><guid isPermaLink="false">https://technofile.substack.com/p/build-multi-agent-apps-with-openais</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Wed, 25 Jun 2025 10:34:13 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ylrv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bf2f3f4-8d5d-4964-9404-7ee3f064194a_1000x495.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!ylrv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bf2f3f4-8d5d-4964-9404-7ee3f064194a_1000x495.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!ylrv!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bf2f3f4-8d5d-4964-9404-7ee3f064194a_1000x495.png 424w, /__u/substackcdn.com/image/fetch/$s_!ylrv!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bf2f3f4-8d5d-4964-9404-7ee3f064194a_1000x495.png 848w, /__u/substackcdn.com/image/fetch/$s_!ylrv!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bf2f3f4-8d5d-4964-9404-7ee3f064194a_1000x495.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ylrv!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bf2f3f4-8d5d-4964-9404-7ee3f064194a_1000x495.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!ylrv!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bf2f3f4-8d5d-4964-9404-7ee3f064194a_1000x495.png" width="1200" height="594" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4bf2f3f4-8d5d-4964-9404-7ee3f064194a_1000x495.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:495,&quot;width&quot;:1000,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:&quot;center&quot;,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!ylrv!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bf2f3f4-8d5d-4964-9404-7ee3f064194a_1000x495.png 424w, /__u/substackcdn.com/image/fetch/$s_!ylrv!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bf2f3f4-8d5d-4964-9404-7ee3f064194a_1000x495.png 848w, /__u/substackcdn.com/image/fetch/$s_!ylrv!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bf2f3f4-8d5d-4964-9404-7ee3f064194a_1000x495.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ylrv!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bf2f3f4-8d5d-4964-9404-7ee3f064194a_1000x495.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Agent orchestration</figcaption></figure></div><p>Some agent framework devs seem to believe that complexity is a virtue. They revel in building complex layers of abstraction on top of fundamentally simple ideas. However, I tend to go along with Einstein&#8217;s maxim, &#8220;<em>Everything should be made as simple as possible, but not simpler&#8221;.</em> </p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands on Data Visualization, Data Science, AI and Python is a reader-supported publication. To receive new posts and support my work, consider becoming a subscriber.  </p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>OpenAI takes a refreshingly different approach to other framework developers&#8202;: they don&#8217;t try to be clever, they try to be clear.</p><p>I walk through how the SDK makes building multi-agent apps refreshingly simple. If you&#8217;ve been struggling with bloated frameworks, this might be just what you need.</p><p>The post is freely available via this link:</p><h3><a href="https://medium.com/ai-advances/how-to-build-multi-agent-apps-with-openais-agent-sdk-343adeb50424?sk=f5df35777dd8d96e49feee7dcb8b785c">Build Multi-Agent Apps with OpenAI&#8217;s Agent SDK</a></h3><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/build-multi-agent-apps-with-openais?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/build-multi-agent-apps-with-openais?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands on Data Visualization, Data Science, AI and Python is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber. Or just follow me!</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Past, Present, and Forecasts: Time Series Visualization with Style]]></title><description><![CDATA[Add clarity to Plotly charts by combining line styles, annotations, and background shading.]]></description><link>https://technofile.substack.com/p/past-present-and-forecasts-time-series</link><guid isPermaLink="false">https://technofile.substack.com/p/past-present-and-forecasts-time-series</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Tue, 08 Apr 2025 17:49:05 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!lGl6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div><hr></div><p><em>I&#8217;ve been reading Cole Nussbaumer Knaflic&#8217;s book</em> Storytelling with Data <em>(see Notes) - it&#8217;s quite illuminating. However, the author does not attempt to provide any implementation details, so I&#8217;m trying to remedy that.</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!lGl6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!lGl6!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png 424w, /__u/substackcdn.com/image/fetch/$s_!lGl6!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png 848w, /__u/substackcdn.com/image/fetch/$s_!lGl6!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png 1272w, /__u/substackcdn.com/image/fetch/$s_!lGl6!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!lGl6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png" width="1280" height="701" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:701,&quot;width&quot;:1280,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:974339,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://technofile.substack.com/i/160880387?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!lGl6!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png 424w, /__u/substackcdn.com/image/fetch/$s_!lGl6!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png 848w, /__u/substackcdn.com/image/fetch/$s_!lGl6!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png 1272w, /__u/substackcdn.com/image/fetch/$s_!lGl6!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13b489e3-5d4c-4457-b066-e7723f93c7f7_1280x701.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>When working with time series data, we often blend the certainty of historical records with the uncertainty of future projections. This is particularly true when dealing with financial data, where you tell a story of how current events might influence future trends. But if current and future data are rendered similarly in a chart, your audience might miss the difference or misinterpret your insights.</p><p>In this article, we&#8217;ll use Python and Plotly to visualize a time series where the past and future are clearly distinguished using thoughtful design choices. Whether you&#8217;re presenting forecasts, planning reports, or just want cleaner charts, this guide will help you level up your data storytelling.</p><div><hr></div><h3>Why Visual Distinction Matters</h3><p>When visualizing time series data, it&#8217;s easy to fall into the trap of treating all data equally. But there&#8217;s clearly a huge difference between what <em>has already happened</em> and what we <em>expect</em> to happen. If we don&#8217;t make that distinction visually clear, we might risk confusing the audience.</p><p>Say we&#8217;re presenting a forecast of sales growth. If our projected values are rendered with the same styling as historical data, are we implying that the future is just as certain as the past?</p><p>Visual design is our opportunity to <strong>signal uncertainty</strong>. A dashed line can indicate something is estimated. A shaded background might subtly cue that we&#8217;re entering a new phase. An annotation helps clarify meaning right on the chart, reducing the need for footnotes or explanations in your text.</p><p>Good design doesn&#8217;t just make better-looking charts&#8202;&#8212;&#8202;it makes them <strong>more honest</strong> and <strong>more effective</strong>.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/past-present-and-forecasts-time-series?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/past-present-and-forecasts-time-series?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><h4>Setting Up Your Data</h4><p>We&#8217;ll start with some fictional data and build a chart step by step. We will use Plotly Graphic Objects, as this library is straightforward to use and gives us more flexibility than Plotly Express.</p><p>I&#8217;ll present the code as cells from a Jupyter Notebook (the code will be available in my GitHub repo shortly after publication&#8202;&#8212;&#8202;see the link at the end of the article). If you prefer a plain old Python program, then just concatenate the code cells and it should work fine.</p><p>Before we define the data, we should import the libraries.</p><pre><code>import plotly.graph_objects as go
import pandas as pd

import plotly.io as pio
pio.templates.default = "plotly_white"</code></pre><p>Now, I must admit to having a thing about the default Plotly theme: I don&#8217;t much like it, so I almost always set the default theme to &#8216;plotly_white&#8217;, which I find to have a much cleaner look. Also, for this exercise, we want the plain white background that this theme gives us. The last two lines of code ensure that this theme is used throughout.</p><p>The data is just a set of integers and dates. We can imagine that they are sales figures of some sort, although this is not important. The important thing is that they are split into historical figures and projected ones. The data covers 15 years from 2015 to 2029, and I&#8217;m assuming that you are reading this in 2025, so the first 9 years are historical data and the final 6 years are predicted values.</p><pre><code># Sample data
data = {
    "Date": pd.date_range(start="2015-01-01", periods=15, freq="YE"),
    "Value": [10, 15, 20, 25, 30, 20, 35, 40, 38, 45, 50, 55, 60, 62, 65],
}

df = pd.DataFrame(data)

# Split into historical and projected data
historical = df.iloc[:10]  # First 10 years
projection = df.iloc[9:]   # Last 6 years</code></pre><p>The sample data is created as a range of 15 datetimes with a frequency of 1 year and a list of 15 integer values. We create a data frame from this and then split the original dataframe into the first 10 and last 5 years. The result is two dataframes <code>historical</code> and <code>projection</code> which contain the historical data and the predicted data, respectively.</p><h4>3. Plotting with Plotly Graphic Objects</h4><p>To create a chart with Plotly Graphic Objects (GO), we first create a GO object and then add traces (i.e. plots).</p><p>To plot a line chart, we use the method <code>go.scatter()</code> to produce a trace and add that to the figure. That&#8217;s right, a scatter plot. But we set the <code>mode</code> parameter to &#8216;lines&#8217;, which tells the method to use lines instead of dots as the marker for plotting&#8202;&#8212;&#8202;a scatter plot that uses lines to plot each point is, of course, a line plot.</p><p>The code to plot the historical data is shown below where you can see that we set the x and y parameters to the Date and Value fields of the dataframe and specified the line colour to be blue.</p><pre><code># Create the figure
fig = go.Figure()

# Add historical data
fig.add_trace(go.Scatter(
    x=historical["Date"], 
    y=historical["Value"], 
    mode="lines", 
    name="Historical",
    line=dict(color="blue")
))

fig.show()</code></pre><p>The resulting plot is shown below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!6fWV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f9e547-4368-4910-9192-4cef628a028c_880x399.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!6fWV!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f9e547-4368-4910-9192-4cef628a028c_880x399.png 424w, /__u/substackcdn.com/image/fetch/$s_!6fWV!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f9e547-4368-4910-9192-4cef628a028c_880x399.png 848w, /__u/substackcdn.com/image/fetch/$s_!6fWV!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f9e547-4368-4910-9192-4cef628a028c_880x399.png 1272w, /__u/substackcdn.com/image/fetch/$s_!6fWV!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f9e547-4368-4910-9192-4cef628a028c_880x399.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!6fWV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f9e547-4368-4910-9192-4cef628a028c_880x399.png" width="880" height="399" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/48f9e547-4368-4910-9192-4cef628a028c_880x399.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:399,&quot;width&quot;:880,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!6fWV!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f9e547-4368-4910-9192-4cef628a028c_880x399.png 424w, /__u/substackcdn.com/image/fetch/$s_!6fWV!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f9e547-4368-4910-9192-4cef628a028c_880x399.png 848w, /__u/substackcdn.com/image/fetch/$s_!6fWV!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f9e547-4368-4910-9192-4cef628a028c_880x399.png 1272w, /__u/substackcdn.com/image/fetch/$s_!6fWV!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48f9e547-4368-4910-9192-4cef628a028c_880x399.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>That is the first 10 years of data.</p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands on Data Visualization, Data Science, AI and Python is a reader-supported publication. See the end of this article for more details.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p>Now let&#8217;s add in the projected data.</p><pre><code># Add projected data with a dashed line
fig.add_trace(go.Scatter(
    x=projection["Date"], y=projection["Value"], mode="lines", name="Projection",
    line=dict(color="blue", dash="dash")
))

fig.show()</code></pre><p>This is pretty similar to the previous code, but it uses the second dataframe and sets the line style to be dashed. Adding this trace creates a new plot that builds on the old one.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!QQi9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5e62034-2fd4-4536-a501-2445d6595da6_880x399.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!QQi9!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5e62034-2fd4-4536-a501-2445d6595da6_880x399.png 424w, /__u/substackcdn.com/image/fetch/$s_!QQi9!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5e62034-2fd4-4536-a501-2445d6595da6_880x399.png 848w, /__u/substackcdn.com/image/fetch/$s_!QQi9!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5e62034-2fd4-4536-a501-2445d6595da6_880x399.png 1272w, /__u/substackcdn.com/image/fetch/$s_!QQi9!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5e62034-2fd4-4536-a501-2445d6595da6_880x399.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!QQi9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5e62034-2fd4-4536-a501-2445d6595da6_880x399.png" width="880" height="399" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b5e62034-2fd4-4536-a501-2445d6595da6_880x399.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:399,&quot;width&quot;:880,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!QQi9!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5e62034-2fd4-4536-a501-2445d6595da6_880x399.png 424w, /__u/substackcdn.com/image/fetch/$s_!QQi9!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5e62034-2fd4-4536-a501-2445d6595da6_880x399.png 848w, /__u/substackcdn.com/image/fetch/$s_!QQi9!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5e62034-2fd4-4536-a501-2445d6595da6_880x399.png 1272w, /__u/substackcdn.com/image/fetch/$s_!QQi9!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5e62034-2fd4-4536-a501-2445d6595da6_880x399.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Plotly GO has automatically added a legend so that we can see what the different traces mean. However, even without that textual clue, it is very clear from the visual look of the plots that the data are different.</p><h4>Enhancing with Graph Objects</h4><p>It is hard to envisage a graph that does not need some sort of textual description to set the context. So, let&#8217;s add some basic text: a title and labels for the axes.</p><pre><code># Update layout
fig.update_layout(
    title="Historical Sales Data and Projected Sales",
    xaxis_title="Year",
    yaxis_title="Units Sold",
    xaxis=dict(showgrid=False),
    yaxis=dict(showgrid=True),
    showlegend=False
)

# Show plot
fig.show()</code></pre><p>The <code>update_layout</code> method does exactly what it says, it allows us to change aspects of the plot. Here we have added the text fields as mentioned and set the grid to horizontal lines only. We also removed the legend.</p><p>Here&#8217;s the new version.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!uuKl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf35d71e-7b4b-45f5-82fa-b57857db6edf_804x450.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!uuKl!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf35d71e-7b4b-45f5-82fa-b57857db6edf_804x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!uuKl!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf35d71e-7b4b-45f5-82fa-b57857db6edf_804x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!uuKl!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf35d71e-7b4b-45f5-82fa-b57857db6edf_804x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!uuKl!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf35d71e-7b4b-45f5-82fa-b57857db6edf_804x450.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!uuKl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf35d71e-7b4b-45f5-82fa-b57857db6edf_804x450.png" width="804" height="450" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bf35d71e-7b4b-45f5-82fa-b57857db6edf_804x450.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:450,&quot;width&quot;:804,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!uuKl!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf35d71e-7b4b-45f5-82fa-b57857db6edf_804x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!uuKl!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf35d71e-7b4b-45f5-82fa-b57857db6edf_804x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!uuKl!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf35d71e-7b4b-45f5-82fa-b57857db6edf_804x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!uuKl!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbf35d71e-7b4b-45f5-82fa-b57857db6edf_804x450.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>That is looking good, already, but we are going to further distinguish between the two types of data.</p><p>The following code cell adds a shaded area to the projected data.</p><pre><code># Add a shaded background for the projection period
fig.add_shape(
    type="rect",
    x0=projection["Date"].iloc[0], x1=projection["Date"].iloc[-1],
    y0=0, y1=1,  # Covers full y-axis
    xref="x", yref="paper",
    fillcolor="lightblue", opacity=0.3, layer="below"
)
fig.show()</code></pre><p>Next, we add a textual annotation to describe that area.</p><pre><code># Add annotation for projection period
fig.add_annotation(
    x=projection["Date"].iloc[2],  # Middle of the projection period
    y=max(df["Value"]) * 1.1,  # Slightly above max value
    text="Projected data",
    showarrow=False,
)
fig.show()</code></pre><p>The chart now looks like this.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!-Ce4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88c18752-5198-4929-a097-2b25109478ea_804x450.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!-Ce4!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88c18752-5198-4929-a097-2b25109478ea_804x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!-Ce4!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88c18752-5198-4929-a097-2b25109478ea_804x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!-Ce4!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88c18752-5198-4929-a097-2b25109478ea_804x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!-Ce4!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88c18752-5198-4929-a097-2b25109478ea_804x450.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!-Ce4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88c18752-5198-4929-a097-2b25109478ea_804x450.png" width="804" height="450" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/88c18752-5198-4929-a097-2b25109478ea_804x450.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:450,&quot;width&quot;:804,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!-Ce4!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88c18752-5198-4929-a097-2b25109478ea_804x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!-Ce4!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88c18752-5198-4929-a097-2b25109478ea_804x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!-Ce4!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88c18752-5198-4929-a097-2b25109478ea_804x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!-Ce4!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F88c18752-5198-4929-a097-2b25109478ea_804x450.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The projections are now easily distinguished as they are contained in that shaded box.</p><p>For consistency, I have written code to similarly contain the historical data. Frankly, I&#8217;m not sure that this is absolutely necessary, but here it is anyway.</p><pre><code># Add a shaded background for the historical period
fig.add_shape(
    type="rect",
    x0=historical["Date"].iloc[0], x1=historical["Date"].iloc[-1],
    y0=0, y1=1,  # Covers full y-axis
    xref="x", yref="paper",
    fillcolor="lightgrey", opacity=0.3, 
    layer="below"
)

# Add annotation for historical period
fig.add_annotation(
    x=historical["Date"].iloc[2],  # Middle of the projection period
    y=max(df["Value"]) * 1.1,  # Slightly above max value
    text="Historical Data",
    showarrow=False,
)

fig.show()</code></pre><p>This treats the historical data in the same way as the projections but the shading is a different colour.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!1BuB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd30dc6ba-0388-4de2-8468-60ebe8ed847c_804x450.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!1BuB!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd30dc6ba-0388-4de2-8468-60ebe8ed847c_804x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!1BuB!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd30dc6ba-0388-4de2-8468-60ebe8ed847c_804x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!1BuB!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd30dc6ba-0388-4de2-8468-60ebe8ed847c_804x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!1BuB!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd30dc6ba-0388-4de2-8468-60ebe8ed847c_804x450.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!1BuB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd30dc6ba-0388-4de2-8468-60ebe8ed847c_804x450.png" width="804" height="450" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d30dc6ba-0388-4de2-8468-60ebe8ed847c_804x450.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:450,&quot;width&quot;:804,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!1BuB!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd30dc6ba-0388-4de2-8468-60ebe8ed847c_804x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!1BuB!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd30dc6ba-0388-4de2-8468-60ebe8ed847c_804x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!1BuB!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd30dc6ba-0388-4de2-8468-60ebe8ed847c_804x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!1BuB!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd30dc6ba-0388-4de2-8468-60ebe8ed847c_804x450.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The resulting chart clearly shows the purpose of each section of the data and so the chart does not require a legend.</p><h4>Annotating specific events</h4><p>If you had been hiding under a rock for the last few years, or have a very short memory, then you might be confused by the slump in sales in the middle of the historical period. To allay the fears of sales executives who are not paying attention, we can add text to the graphs to explain such anomalies.</p><p>Plotly GO allows us to add text, as we saw above, but we can also add nice little arrows to highlight a point in the graph.</p><pre><code># Add annotation for COVID in 2020
fig.add_annotation(
    x=pd.Timestamp("2020-12-31"),  # Year 2020
    y=25,  # Position above the value for 2020
    text="COVID Slump",
    showarrow=True,
    arrowhead=2,
    arrowsize=1,
    arrowcolor="red",
    ax=0, ay=-60,  # Arrow pointing down
    font=dict(size=12, color="red")
)
# Show plot
fig.show()</code></pre><p>The code above positions a text annotation and defines an arrow that points to a particular part in the graph.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!doJx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc47d9bd-af2a-4c8f-95a2-583dd1d1e9da_804x450.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!doJx!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc47d9bd-af2a-4c8f-95a2-583dd1d1e9da_804x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!doJx!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc47d9bd-af2a-4c8f-95a2-583dd1d1e9da_804x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!doJx!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc47d9bd-af2a-4c8f-95a2-583dd1d1e9da_804x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!doJx!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc47d9bd-af2a-4c8f-95a2-583dd1d1e9da_804x450.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!doJx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc47d9bd-af2a-4c8f-95a2-583dd1d1e9da_804x450.png" width="804" height="450" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bc47d9bd-af2a-4c8f-95a2-583dd1d1e9da_804x450.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:450,&quot;width&quot;:804,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!doJx!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc47d9bd-af2a-4c8f-95a2-583dd1d1e9da_804x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!doJx!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc47d9bd-af2a-4c8f-95a2-583dd1d1e9da_804x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!doJx!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc47d9bd-af2a-4c8f-95a2-583dd1d1e9da_804x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!doJx!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc47d9bd-af2a-4c8f-95a2-583dd1d1e9da_804x450.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>That is my final version of the graph.</p><h4>Final Thoughts</h4><p>We&#8217;ve demonstrated how Plotly Graphic Objects can be used to create clear and easy-to-interpret graphs.</p><p>Different line styles help distinguish between various data types, and grouping them within shaded boxes further enhances clarity.</p><p>Textual annotations and labels are crucial for providing context and can also be used to draw attention to specific areas of interest.</p><p>Data visualization is fundamentally about communication, and I hope the examples shown highlight how well-designed, visually appealing charts can enhance that communication.</p><p>While the data used here is simple and fictional, the techniques are applicable to your own real-world datasets.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share&quot;,&quot;text&quot;:&quot;Share Hands on Data Visualization, Data Science, AI and Python&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share Hands on Data Visualization, Data Science, AI and Python</span></a></p><div><hr></div><p>As ever, thanks for reading and I hope that this has been useful. To see more of my articles, follow me on <a href="https://medium.com/@alan-jones">Medium</a> or subscribe to my <a href="/__u/technofile.substack.com/">Substack</a>.</p><p>The code and data for this article can be found in my GitHub repo. I will place a link to it <em><a href="https://github.com/DataVizandAI/public_code/tree/main/data-viz-projections">here</a> </em>shortly after publication.</p><p>Notes</p><ol><li><p>I have been very much influenced by Cole Nussbaumer Knaflic&#8217;s book <em>Storytelling with Data: A Data Visualization Guide for Business Professionals. </em>It&#8217;s well worth a read if data visualisation is your thing. It&#8217;s available <a href="https://amzn.to/4iVbiBX">here</a> (affiliate link).</p></li><li><p>I messed up the presentation of the date of the Covid pandemic, but I&#8217;d already created all the code and images and practically finished the article before I noticed. And I&#8217;m too darned lazy to do it over. Sorry!</p></li></ol><div><hr></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands on Data Visualization, Data Science, AI and Python is a reader-supported publication. </p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p><em>Currently, although paid subscriptions are open, you won&#8217;t get anything extra - this may change in the future. But if you feel inclined to support my work regularly, you could do this. If you don&#8217;t want to, that&#8217;s fine, just take out a free subscription. Or, if you don&#8217;t want to get stuff in your inbox, just follow me.</em></p><p><em>Or&#8230;</em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://ko-fi.com/alan_jones" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 424w, /__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 848w, /__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 1272w, /__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!0qyq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png" width="228" height="57.39310344827586" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:146,&quot;width&quot;:580,&quot;resizeWidth&quot;:228,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://ko-fi.com/alan_jones&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 424w, /__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 848w, /__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 1272w, /__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div>]]></content:encoded></item><item><title><![CDATA[Structured Outputs for Consistent LLM Responses]]></title><description><![CDATA[Stop being driven crazy by inconsistent responses]]></description><link>https://technofile.substack.com/p/structured-outputs-for-consistent</link><guid isPermaLink="false">https://technofile.substack.com/p/structured-outputs-for-consistent</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Sun, 06 Apr 2025 18:31:09 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!RBhs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c8bbec-cfdc-4b56-9dc2-368b98045acd_1320x880.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div><hr></div><h4></h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!RBhs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c8bbec-cfdc-4b56-9dc2-368b98045acd_1320x880.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!RBhs!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c8bbec-cfdc-4b56-9dc2-368b98045acd_1320x880.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!RBhs!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c8bbec-cfdc-4b56-9dc2-368b98045acd_1320x880.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!RBhs!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c8bbec-cfdc-4b56-9dc2-368b98045acd_1320x880.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!RBhs!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c8bbec-cfdc-4b56-9dc2-368b98045acd_1320x880.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!RBhs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c8bbec-cfdc-4b56-9dc2-368b98045acd_1320x880.jpeg" width="1320" height="880" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/02c8bbec-cfdc-4b56-9dc2-368b98045acd_1320x880.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:880,&quot;width&quot;:1320,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!RBhs!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c8bbec-cfdc-4b56-9dc2-368b98045acd_1320x880.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!RBhs!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c8bbec-cfdc-4b56-9dc2-368b98045acd_1320x880.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!RBhs!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c8bbec-cfdc-4b56-9dc2-368b98045acd_1320x880.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!RBhs!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02c8bbec-cfdc-4b56-9dc2-368b98045acd_1320x880.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Neat structures&#8202;&#8212;&#8202;Photo by <a href="https://unsplash.com/@johnjac?utm_source=medium&amp;utm_medium=referral">John Jackson</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure></div><p>Ask an LLM a well-put question and the likelihood is that you will get a sensible answer. Ask the same question again, though, and you might get an equally sensible but slightly different answer.</p><p>For example, I was trying to get an API to write executable code, and it turned out to be a challenge because no matter how many times and in how many places I told it not to, once in a while, it would put Markdown-style fencing around the code, making it syntactically wrong. (OK, it's not too much of a problem filtering them out, but still&#8230;)</p><p>The responses from an LLM vary because there is always some randomness in processing the result. When using an API, you can reduce this with the &#8216;temperature&#8217; setting, but, nevertheless, there will always be some variation.</p><p>If you are a human talking to ChatGPT, Gemini, Claude, etc., then this won&#8217;t matter. If the wording of the response is a bit different or the layout has changed, you still understand.</p><p>But if you are a computer program tuned to process one type of response, then even a slight variation may cause an error.</p><p>The solution is to use structured outputs to guarantee a consistent result.</p><p>We are going to look at how to create structured outputs using <a href="https://ai.pydantic.dev/">PydanticAI </a>and apply them to a couple of use cases. First, we&#8217;ll see how structured outputs work, and then we&#8217;ll process unstructured data into a structured format that can be used programmatically. We&#8217;ll also see how we can generate runnable code reliably.</p><p>Why PydanticAI?</p><p>First, it&#8217;s open source and easy to use. And second, it is model-neutral: you can use it with several different LLMs (unlike OpenAI&#8217;s structured outputs, for example, that only work with their API).</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/structured-outputs-for-consistent?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/structured-outputs-for-consistent?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><h4>Why Use Structured Outputs from an LLM</h4><p>There are several benefits in using structured outputs over conventional responses, for example:</p><ul><li><p>Reliability is improved&#8212; enforcing a predictable format will ensure the LLM response is consistent, and no complex parsing of the LLM response is required</p></li><li><p>Integration is easier&#8202;&#8212;&#8202;elements of a structured response can be used directly in an application or more easily processed into a required format</p></li><li><p>Development is faster&#8202;&#8212;&#8202;less code is required, and testing is less complex</p></li></ul><p>Altogether, if you aim to use LLM responses in an application, structured outputs make life more straightforward.</p><h4>What does a structured output look like</h4><p>Typically, we are talking about JSON-like responses with specified fields and types. Such a structure can be easily used directly in a Python program as an array or dictionary, or may be converted into a Pandas dataframe or other data structure.</p><p>Take a look at the following message from a customer and the prompt.</p><pre><code>complaint = """Hi, this is Jane. My internet has been down for two days 
               and I'm very upset."""

prompt = f"""
Extract the following information from the customer complaint:

Customer Name, Issue Category, Sentiment, Urgency.

Return your answer as a JSON object.
{complaint}
"""</code></pre><p>We&#8217;re asking the LLM to analyse the customer complaint and produce a JSON response that will look something like the following.</p><pre><code>{
  "customer_name": "Jane",
  "issue_category": "Connectivity",
  "sentiment": "Frustrated",
  "urgency": "High"
}</code></pre><p>In this experiment, we will specify the structured output format a little more formally than this, and since the framework we are using is PydanticAI, it won&#8217;t be any surprise that we use Pydantic to define the output structure.</p><h4>PydanticAI</h4><p>PydanticAI is a fairly new framework for constructing AI agents. It&#8217;s MIT-licensed and pretty easy to use.</p><p>The following code is in the form of Jupyter Notebook cells, but you ought to be able to construct a plain old Python file from it, too. I&#8217;ll pop a link to the source code at the end of the article.</p><p>First things first, we need to import the Pydantic library, and so that it doesn&#8217;t interfere with the Jupyter runtime, we need to import <code>nest_asyncio</code> and run the <code>apply</code> method. You won&#8217;t need this in a plain Python program.</p><pre><code>from pydantic_ai import Agent
import nest_asyncio
nest_asyncio.apply()</code></pre><h4>Simple structured output</h4><p>This example comes from the PydanticAI documentation. We ask a simple question, and the answer should be a city. The response should be the name of the city and the country that it is in.</p><p>You can see in the code below that we have a very straightforward Pydantic declaration of a class <code>CityLocation</code>. It consists of two strings, one for the city name and the other for the country name.</p><p>The agent is defined with the model type and the <code>result_type</code> set to <code>CityLocation</code> , meaning that the response must be of that type.</p><p>We then run the agent with a query &#8216;Where were the olympics held in 2012?&#8217; and print the result. This can be seen in the panel below the code.</p><pre><code>from pydantic import BaseModel

class CityLocation(BaseModel):
    city: str
    country: str

agent = Agent('openai:gpt-4o-mini', result_type=CityLocation)
result = agent.run_sync('Where were the olympics held in 2012?')
print(result.data)</code></pre><pre><code>city='London' country='United Kingdom'</code></pre><p>We could ask any question where the result is a city and receive a response in the same format. But what if the question does not produce a valid output? This could be due to an error in the LLM processing or because it is simply impossible to provide a suitable response to the question given.</p><p>In the case of an LLM failure, you probably need to validate the response against the Pydantic model and retry the query. There is a whole section on validation in the <a href="https://ai.pydantic.dev/results/#streaming-structured-responses">PydanticAI documents</a> that deals with this, and it would take another article to deal with it, so I won&#8217;t go into it here.</p><p>However, when a valid answer isn&#8217;t possible, a simple strategy is to ask the LLM to fill in fields in the response that indicate whether a response is valid or not, e.g.</p><pre><code>from pydantic import BaseModel

class CityLocation(BaseModel):
    city: str
    country: str
    valid: bool = True
    error: str = None

prompt = """If the answer is not a city, 
            return empty strings for the city and country, 
            return valid=False and an error message."""
agent = Agent('openai:gpt-4o-mini', 
              result_type=CityLocation, 
              system_prompt=prompt)</code></pre><p>Here are a couple of queries, one bad, the other good:</p><pre><code>result = agent.run_sync('What is a fish?')
print(result.data)

result = agent.run_sync('In what city was the soccer world cup final last played?')
print(result.data)</code></pre><p>And the results:</p><pre><code>city='' country='' valid=False error='The answer provided is not a city.'
city='Lusail' country='Qatar' valid=True error=None</code></pre><p>So, that&#8217;s how to get structured outputs from an LLM. Let&#8217;s take a look at a couple of practical examples that might form part of an application.</p><p>We&#8217;ll first look at how we can transform unstructured customer feedback into a form that we can load into a Pandas dataframe for processing, and then we&#8217;ll see how we can generate runnable Python code.</p><h3>Structured customer feedback</h3><p>I&#8217;m going to use fictitious customer feedback similar to my AI for BI article <em><a href="https://medium.com/data-science/transform-customer-feedback-into-actionable-insights-with-crewai-and-streamlit-06b6f482f5ae">Transform Customer Feedback into Actionable Insights with CrewAI and Streamlit</a>. </em>It is a set of ratings and comments about products from a made-up online shoe store.</p><p>I&#8217;ve stored the comments in a Markdown file called <em>shoes.md,</em> and so we can read it like this:</p><pre><code>fb_raw = "shoes.md"
with open(fb_raw, 'r') as f:
    fb = f.read()

print(fb)</code></pre><p>When printed, it looks like the following: a star rating and a comment about the product.</p><pre><code># Customer feedback

### CloudStrider Sneakers

1. Stars: 2  
   "The shoes were super comfortable initially, but after just two months, the sole started to peel off! Really disappointed with the durability."  
2. Stars: 1  
   "I ordered my usual size, but these sneakers were way too tight. Had to return them. The sizing is totally off."  
3. Stars: 3  
   "Great for short runs, but they hold onto odors even after washing. Not ideal for heavy use."  
4. Stars: 5  
   "Extremely lightweight and breathable. Perfect for casual jogging. No issues so far!"
### PeakTrek Hikers
1. Stars: 1  
   "These boots claim to be waterproof, but my feet were soaked after just walking through damp grass. Not worth it."  
2. Stars: 2  
   "I slipped multiple times on rocky trails because the soles don&#226;&#8364;&#8482;t grip well on wet surfaces. Not safe for serious hikes."  
3. Stars: 4  
   "The boots are sturdy and provide decent ankle support, but I wish the padding was thicker for longer treks."  
4. Stars: 5  
   "Used these for a weekend hike in the mountains, and they held up really well. No blisters, and they felt solid."</code></pre><p>I want to transform this into a structured format, and I use the following prompt:</p><pre><code>description=f""" 
            Analyse '{fb}' the data provided - it is in Markdown format. 
            The data is about the range of shoes in an online shop each with 
            set of messages from customers giving feedback about the shoes that they have purchased.
            """</code></pre><p>This is used along with two Pydantic models: the first is the format of an individual comment, while the second defines a list of those comments. An <code>Enum</code> is used to define the possible sentiment values.</p><p>The agent is then called using the list as the structured output definition.</p><pre><code>from pydantic import BaseModel
from enum import Enum

class Sentiment(str, Enum):
    negative = 'negative'
    neutral = 'neutral'
    positive = 'positive'

class feedback_report_shoe(BaseModel):
    product: str
    overall_rating: int  
    issue: str 
    review: str
    sentiment: Sentiment

class feedback_report(BaseModel):
    feedback: list[feedback_report_shoe]

agent = Agent('openai:gpt-4o-mini', result_type=feedback_report)
result = agent.run_sync(description)</code></pre><p>The result, in JSON format, can be seen using the following print statement.</p><pre><code>print(result.data.model_dump_json(indent=2))</code></pre><p>And here is a sample of that output:</p><pre><code>{
  "feedback": [
    {
      "product": "CloudStrider Sneakers",
      "overall_rating": 2,
      "issue": "Durability",
      "review": "The shoes were super comfortable initially, but after just two months, the sole started to peel off! Really disappointed with the durability.",
      "sentiment": "negative"
    },
    {
      "product": "CloudStrider Sneakers",
      "overall_rating": 1,
      "issue": "Sizing",
      "review": "I ordered my usual size, but these sneakers were way too tight. Had to return them. The sizing is totally off.",
      "sentiment": "negative"
    }
...

  ]
}</code></pre><p>Now that we have a nicely structured output, we can easily convert it into a dataframe for further processing.</p><pre><code>import pandas as pd
df = pd.DataFrame([dict(f) for f in result.data.feedback])
df['sentiment'] = df['sentiment'].apply(lambda x: x.value)
df</code></pre><p>This code will give us the dataframe illustrated below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!t9_7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fece3f1b4-31ce-4ccf-8069-f79d0d062b6c_880x581.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!t9_7!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fece3f1b4-31ce-4ccf-8069-f79d0d062b6c_880x581.png 424w, /__u/substackcdn.com/image/fetch/$s_!t9_7!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fece3f1b4-31ce-4ccf-8069-f79d0d062b6c_880x581.png 848w, /__u/substackcdn.com/image/fetch/$s_!t9_7!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fece3f1b4-31ce-4ccf-8069-f79d0d062b6c_880x581.png 1272w, /__u/substackcdn.com/image/fetch/$s_!t9_7!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fece3f1b4-31ce-4ccf-8069-f79d0d062b6c_880x581.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!t9_7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fece3f1b4-31ce-4ccf-8069-f79d0d062b6c_880x581.png" width="880" height="581" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ece3f1b4-31ce-4ccf-8069-f79d0d062b6c_880x581.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:581,&quot;width&quot;:880,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!t9_7!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fece3f1b4-31ce-4ccf-8069-f79d0d062b6c_880x581.png 424w, /__u/substackcdn.com/image/fetch/$s_!t9_7!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fece3f1b4-31ce-4ccf-8069-f79d0d062b6c_880x581.png 848w, /__u/substackcdn.com/image/fetch/$s_!t9_7!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fece3f1b4-31ce-4ccf-8069-f79d0d062b6c_880x581.png 1272w, /__u/substackcdn.com/image/fetch/$s_!t9_7!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fece3f1b4-31ce-4ccf-8069-f79d0d062b6c_880x581.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>We can process the data further, for example, ranking the products according to their star rating.</p><pre><code>average_ratings = df.groupby('product')['overall_rating'].mean()
average_ratings = average_ratings.sort_values(ascending=False)
print(average_ratings)</code></pre><p>We first grouped the products, calculated the mean of the rating and then sorted them.</p><pre><code>BounceMax Runners        4.75
EcoStep Slip-Ons         4.50
LuxeLace Oxfords         4.50
PeakTrek Hikers          3.00
CloudStrider Sneakers    2.75
SwiftShine Heels         2.50</code></pre><p>In this example, getting the LLM to structure the data makes it easy for us to process it. Now, let&#8217;s look at my code generation problem.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/structured-outputs-for-consistent?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/structured-outputs-for-consistent?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><h4>Unstructured code generation</h4><p>LLMs are quite proficient at producing code, but, as I discussed earlier, getting them to produce something consistent and usable is slightly trickier.</p><p>Here is a simple example of code generation. We simply asked the agent to produce a Python function to add two integers.</p><pre><code>from pydantic_ai import Agent

agent = Agent(  
    'openai:gpt-4o-mini',
)

result = agent.run_sync("Write a Python function to add two integers"
                        "together and give an example call")  
print(result.data)</code></pre><pre><code>Here is a simple Python function that takes two integers as input, 
adds them together, and returns the result:

```python
def add_two_integers(a, b):
    """
    Add two integers together.

    Parameters:
    a (int): The first integer.
    b (int): The second integer.

    Returns:
    int: The sum of the two integers.
    """
    return a + b

# Example call
result = add_two_integers(5, 3)
print(result)  # Output: 8
```

In this example, the function `add_two_integers` is defined to take two 
parameters, `a` and `b`. It calculates the sum of these two integers and 
returns the result. The example call at the bottom demonstrates how to use 
the function by adding the integers 5 and 3, resulting in an output of 8.</code></pre><p>The result is typical of a chat-like response and contains exactly the right information. But I cannot use the output to directly run the code because the response is targeted at a human not a computer program.</p><h4>Structured code generation</h4><p>Here is a different version with a Pydantic model defined to split the output into the code section and a commentary.</p><pre><code>class Code_Output(BaseModel):
    code: str
    commentary: str

agent = Agent('openai:gpt-4o-mini', result_type=Code_Output)

result = agent.run_sync("Write a Python function to add two integers" 
                        "together and give an example call")  

</code></pre><p>The <code>code</code> part of the response contains a runnable function&#8202;&#8212;&#8202;no additional information or Markdown fencing, just the code.</p><pre><code>print(result.data.code)</code></pre><pre><code>def add_two_integers(a, b):
    """
    This function takes two integers and returns their sum.
    """
    return a + b</code></pre><p>And the commentary contains the rest of the output.</p><pre><code>print(result.data.commentary)</code></pre><pre><code># Example call
result = add_two_integers(5, 3)
print(result)  # Output: 8

The function 'add_two_integers' is defined to take two integers as parameters 
and return their sum. An example call is provided where the function is 
called with the integers 5 and 3, and the result is printed.</code></pre><p>We can run the code easily. Here is a Notebook cell that does just that. The functional part of the cell is just <code>exec(result.data.code)</code>. The rest of the code ensures that the user can review the code and is warned that running it could cause problems. It is a bad idea to run LLM-generated code unseen unless it is in a sandbox environment such as Docker. LLMs make errors and while it is unlikely that a function to add two integers will cause any harm, we should still check.</p><pre><code>import ipywidgets as widgets

text = widgets.HTML("&lt;h3&gt;Running the code is potentially dangerous&lt;/h3&gt;") 
button = widgets.Button(description="Run it, anyway",
                         button_style='danger')
output = widgets.Output(layout={'border': '1px solid black'})
with output:
    print("Code result:")

display(widgets.VBox([text,button, output]))

def run(b):
    with output:
        exec(result.data.code)

button.on_click(run)

VBox(children=(HTML(value='&lt;h3&gt;Running the code is potentially dangerous&lt;/h3&gt;'), Button(button_style='danger',&#8230;</code></pre><h3>Conclusion</h3><p>Structured outputs are a useful way of ensuring consistency in an LLM&#8217;s response, as I hope these simple examples have illustrated.</p><p>They are easily implemented in PydanticAI: simply define a Pydantic model and use that in the call to the AI agent. The result will be a data structure that is easily used in further coding.</p><p>I haven&#8217;t properly covered what happens if the LLM does not respond as required, which is always a possibility, as this could easily be a lengthy discussion. The method that I showed above only copes with the simplest of errors, and more sophisticated error detection may well be necessary for a particular application, for example, validation against the model and retrying the query - PydanticAI discusses this in their docs.</p><div><hr></div><p>As ever, thanks for reading and I hope that this has been useful. To see more of my articles, follow me on <a href="https://medium.com/@alan-jones">Medium</a> or subscribe to my <a href="/__u/technofile.substack.com/">Substack</a>.</p><p>The code and data for this article can be found in my GitHub repo. I will place a link to it <em><a href="https://github.com/DataVizandAI/public_code/tree/main/structured-outputs">here</a> </em>shortly after publication.</p><div><hr></div><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands on Data Visualization, Data Science, AI and Python is a reader-supported publication. </p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Currently, although paid subscriptions are open, you won&#8217;t get anything extra - this may change in the future. But if you feel inclined to support my work regularly, you could do this. If you don&#8217;t want to, that&#8217;s fine, just take out a free subscription. Or, if you don&#8217;t want to get stuff in your inbox, just follow me.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://ko-fi.com/alan_jones" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 424w, /__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 848w, /__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 1272w, /__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!0qyq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png" width="228" height="57.39310344827586" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:146,&quot;width&quot;:580,&quot;resizeWidth&quot;:228,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:&quot;https://ko-fi.com/alan_jones&quot;,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 424w, /__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 848w, /__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 1272w, /__u/substackcdn.com/image/fetch/$s_!0qyq!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fc9b3be-ebb7-4686-bbc7-2be51d73bf0c_580x146.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div>]]></content:encoded></item><item><title><![CDATA[Data Analysis and Visualization with Gemini and Google Colab ]]></title><description><![CDATA[Let AI take the strain]]></description><link>https://technofile.substack.com/p/data-analysis-and-visualization-with</link><guid isPermaLink="false">https://technofile.substack.com/p/data-analysis-and-visualization-with</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Wed, 02 Apr 2025 17:07:44 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!UmRs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7355152-bca6-47c5-ac31-2f391538e839_1320x880.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!UmRs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7355152-bca6-47c5-ac31-2f391538e839_1320x880.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!UmRs!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7355152-bca6-47c5-ac31-2f391538e839_1320x880.png 424w, /__u/substackcdn.com/image/fetch/$s_!UmRs!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7355152-bca6-47c5-ac31-2f391538e839_1320x880.png 848w, /__u/substackcdn.com/image/fetch/$s_!UmRs!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7355152-bca6-47c5-ac31-2f391538e839_1320x880.png 1272w, /__u/substackcdn.com/image/fetch/$s_!UmRs!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7355152-bca6-47c5-ac31-2f391538e839_1320x880.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!UmRs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7355152-bca6-47c5-ac31-2f391538e839_1320x880.png" width="1320" height="880" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e7355152-bca6-47c5-ac31-2f391538e839_1320x880.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:880,&quot;width&quot;:1320,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!UmRs!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7355152-bca6-47c5-ac31-2f391538e839_1320x880.png 424w, /__u/substackcdn.com/image/fetch/$s_!UmRs!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7355152-bca6-47c5-ac31-2f391538e839_1320x880.png 848w, /__u/substackcdn.com/image/fetch/$s_!UmRs!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7355152-bca6-47c5-ac31-2f391538e839_1320x880.png 1272w, /__u/substackcdn.com/image/fetch/$s_!UmRs!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7355152-bca6-47c5-ac31-2f391538e839_1320x880.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">AI generated image</figcaption></figure></div><p><em>I&#8217;ve been away for a little while, wandering around the woods of rural England, doing very little and not being online. Before I disappeared, I discovered that Google has integrated its Gemini LLM into its online Notebook environment Colab. Here is the result of my experiments in getting Gemini to automatically analyse and visualize data using a public data set about the popularity of various programming languages.</em></p><div><hr></div><p>Ok, forget everything I&#8217;ve said in the past about using AI to create data visualizations. This could make everything else redundant.</p><p>Just open a Google Colab notebook, upload your data and ask its Data Science Agent to do all the work for you.</p><p>Google&#8217;s Data Science Agent is based on Gemini, its LLM offering. It is incorporated into Colab and can simplify data analysis by automating the creation of complete Jupyter notebooks. It has two modes: at the cell level, it lets you prompt Gemini to generate code there in the cell, but it can also generate entire notebooks from data files and a user prompt. Additionally, Gemini can also explain errors in your code and fix them.</p><p>According to Gemini itself, the agent's benefits include:</p><blockquote><p><strong>Fully functional Colab notebooks:</strong> Not just code snippets, but complete, executable notebooks.</p><p><strong>Modifiable solutions:</strong> Easily customize and extend the generated code to fit your specific needs.</p><p><strong>Sharable results:</strong> Collaborate with teammates using standard Colab sharing features.</p><p><strong>Time savings:</strong> Focus on deriving insights from your data instead of wrestling with setup and boilerplate code.</p></blockquote><p>So, let&#8217;s give it a whirl and see how it works.</p><p>We&#8217;ll give it a dataset that tracks the popularity of 30 programming languages over time. Then we&#8217;ll ask it to analyse the data. Gemini will come up with a plan which you can accept (or you can ask for modifications) and it will then execute that plan, creating code cells and executing them to complete the tasks it defined in its plan.</p><p>Later, we&#8217;ll look at what happens when we prompt the agent to produce a more directed plan that specifies our particular interests.</p><p>First, however, we will be lazy, accept a default plan, and let Gemini go its own way.</p><p>You&#8217;ll need a Google account to run Colab. If you are not familiar with it, it is essentially a Jupyter Notebook running on a Google server but with extras. To quote Google&#8217;s Gemini:</p><blockquote><p>&#8220;Colab provides free access to computing resources, including GPUs and TPUs, making it suitable for machine learning, data science, and education&#8221;</p></blockquote><p>It's free to use, but the availability of resources may vary depending on demand. You can find it here: </p><p>https://colab.research.google.com/</p><p>The data and the notebooks for this exercise will be available for download from my Github repo shortly after publication. See the <strong>Notes </strong>below for details.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/data-analysis-and-visualization-with?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/data-analysis-and-visualization-with?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><h4>Colab with Gemini</h4><p>When you first log in to Colab, you need to create a new notebook, which will look very much like a standard Jupyter Notebook. However, below the initial empty code cell, you will be presented with a button that invites you to &#8220;Analyse files with Gemini&#8221;.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!RvQB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0d0df77-c84a-4761-ac19-6f5ed2f64816_484x339.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!RvQB!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0d0df77-c84a-4761-ac19-6f5ed2f64816_484x339.png 424w, /__u/substackcdn.com/image/fetch/$s_!RvQB!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0d0df77-c84a-4761-ac19-6f5ed2f64816_484x339.png 848w, /__u/substackcdn.com/image/fetch/$s_!RvQB!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0d0df77-c84a-4761-ac19-6f5ed2f64816_484x339.png 1272w, /__u/substackcdn.com/image/fetch/$s_!RvQB!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0d0df77-c84a-4761-ac19-6f5ed2f64816_484x339.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!RvQB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0d0df77-c84a-4761-ac19-6f5ed2f64816_484x339.png" width="484" height="339" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b0d0df77-c84a-4761-ac19-6f5ed2f64816_484x339.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:339,&quot;width&quot;:484,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!RvQB!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0d0df77-c84a-4761-ac19-6f5ed2f64816_484x339.png 424w, /__u/substackcdn.com/image/fetch/$s_!RvQB!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0d0df77-c84a-4761-ac19-6f5ed2f64816_484x339.png 848w, /__u/substackcdn.com/image/fetch/$s_!RvQB!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0d0df77-c84a-4761-ac19-6f5ed2f64816_484x339.png 1272w, /__u/substackcdn.com/image/fetch/$s_!RvQB!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0d0df77-c84a-4761-ac19-6f5ed2f64816_484x339.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Click on that and you will be prompted to upload a file. The file I uploaded looks like the screenshot below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!BQrq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9f4903e-90cb-4d0d-9e24-8910f47afa0d_880x265.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!BQrq!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9f4903e-90cb-4d0d-9e24-8910f47afa0d_880x265.png 424w, /__u/substackcdn.com/image/fetch/$s_!BQrq!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9f4903e-90cb-4d0d-9e24-8910f47afa0d_880x265.png 848w, /__u/substackcdn.com/image/fetch/$s_!BQrq!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9f4903e-90cb-4d0d-9e24-8910f47afa0d_880x265.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BQrq!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9f4903e-90cb-4d0d-9e24-8910f47afa0d_880x265.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!BQrq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9f4903e-90cb-4d0d-9e24-8910f47afa0d_880x265.png" width="880" height="265" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c9f4903e-90cb-4d0d-9e24-8910f47afa0d_880x265.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:265,&quot;width&quot;:880,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!BQrq!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9f4903e-90cb-4d0d-9e24-8910f47afa0d_880x265.png 424w, /__u/substackcdn.com/image/fetch/$s_!BQrq!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9f4903e-90cb-4d0d-9e24-8910f47afa0d_880x265.png 848w, /__u/substackcdn.com/image/fetch/$s_!BQrq!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9f4903e-90cb-4d0d-9e24-8910f47afa0d_880x265.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BQrq!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc9f4903e-90cb-4d0d-9e24-8910f47afa0d_880x265.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>It is a simple table of the popularity of programming languages from July 2004 to the end of 2024. The numbers in the language columns are percentages and represent the proportion of users of a language (see <strong>Notes</strong>).</p><p>You should be aware that the data you upload will disappear when you finish your Colab session. (In the notebooks I provide for download, I have substituted the reference to a local file with an external source so the data will be persistent across sessions. You can upload these notebooks to Colab or run them in a local instance of Jupyter.)</p><h4>A generic plan</h4><p>After I uploaded the data, I was invited to &#8216;Analyse Files&#8217;. Having done that, Gemini responded thus:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!yhxF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c4a00a-7648-4b9a-8959-4e0d735412ae_672x589.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!yhxF!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c4a00a-7648-4b9a-8959-4e0d735412ae_672x589.png 424w, /__u/substackcdn.com/image/fetch/$s_!yhxF!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c4a00a-7648-4b9a-8959-4e0d735412ae_672x589.png 848w, /__u/substackcdn.com/image/fetch/$s_!yhxF!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c4a00a-7648-4b9a-8959-4e0d735412ae_672x589.png 1272w, /__u/substackcdn.com/image/fetch/$s_!yhxF!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c4a00a-7648-4b9a-8959-4e0d735412ae_672x589.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!yhxF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c4a00a-7648-4b9a-8959-4e0d735412ae_672x589.png" width="672" height="589" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f7c4a00a-7648-4b9a-8959-4e0d735412ae_672x589.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:589,&quot;width&quot;:672,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!yhxF!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c4a00a-7648-4b9a-8959-4e0d735412ae_672x589.png 424w, /__u/substackcdn.com/image/fetch/$s_!yhxF!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c4a00a-7648-4b9a-8959-4e0d735412ae_672x589.png 848w, /__u/substackcdn.com/image/fetch/$s_!yhxF!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c4a00a-7648-4b9a-8959-4e0d735412ae_672x589.png 1272w, /__u/substackcdn.com/image/fetch/$s_!yhxF!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c4a00a-7648-4b9a-8959-4e0d735412ae_672x589.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The response will be tailored to whatever file you upload, of course.</p><p>You can ask for changes, although for this exercise I accepted the default plan and executed it.</p><p>Time to make a cup of tea.</p><p>Actually, executing the plan doesn&#8217;t take that long with this fairly small file, but with a large dataset, I can imagine you might have to wait a while for Gemini to work through the various tasks.</p><p>Gemini keeps you posted about its progress, gradually ticking off the tasks as they are completed.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Tsl9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04418c7a-4ebc-4cb2-8f67-b468813131a2_330x243.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Tsl9!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04418c7a-4ebc-4cb2-8f67-b468813131a2_330x243.png 424w, /__u/substackcdn.com/image/fetch/$s_!Tsl9!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04418c7a-4ebc-4cb2-8f67-b468813131a2_330x243.png 848w, /__u/substackcdn.com/image/fetch/$s_!Tsl9!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04418c7a-4ebc-4cb2-8f67-b468813131a2_330x243.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Tsl9!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04418c7a-4ebc-4cb2-8f67-b468813131a2_330x243.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Tsl9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04418c7a-4ebc-4cb2-8f67-b468813131a2_330x243.png" width="330" height="243" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/04418c7a-4ebc-4cb2-8f67-b468813131a2_330x243.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:243,&quot;width&quot;:330,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Tsl9!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04418c7a-4ebc-4cb2-8f67-b468813131a2_330x243.png 424w, /__u/substackcdn.com/image/fetch/$s_!Tsl9!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04418c7a-4ebc-4cb2-8f67-b468813131a2_330x243.png 848w, /__u/substackcdn.com/image/fetch/$s_!Tsl9!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04418c7a-4ebc-4cb2-8f67-b468813131a2_330x243.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Tsl9!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04418c7a-4ebc-4cb2-8f67-b468813131a2_330x243.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>And, hey presto, we have a complete notebook with code cells for each task. Sometimes, Gemini will create coding errors. When this happens, it will attempt to retry the code in a new cell. When Gemini runs the notebook, it will run all the cells even though there was an error, but if you try to re-run it, it will stop at that point. To get a fault-free run, you need to manually remove the guilty cell.</p><p>Since we have given no direction on how to proceed, Gemini&#8217;s plan is fairly generic and not necessarily suitable for our purposes. But let&#8217;s see what it has done for us.</p><p>Each task in the plan is coded in a separate Jupyter cell, and this is preceded by a text introduction. We&#8217;ll go through each one.</p><ul><li><p><strong>Data Loading:</strong> This simply loads a local CSV file into a dataframe and prints out the <code>head</code>.</p></li><li><p><strong>Data exploration</strong>: This stage prints out the shape of the dataframe and the datatypes. It checks for missing values (there are none) and then prints statistics for each column (i.e. language).</p></li><li><p><strong>Data cleaning</strong>: Here, the <code>Date</code> column is converted to a datetime format.</p></li><li><p><strong>Data analysis</strong>: This task analyses the trends in programming language popularity over time. It calculates the average popularity for each programming language, determines the peak popularity and corresponding date, identifies significant changes in popularity, and calculates the average popularity per year for each language. The first attempt at doing this failed as Gemini tried to operate on a <code>Year</code> column that it had created, which was not a numerical field. It automatically made a second (successful) attempt to correct the original mistake.</p></li><li><p><strong>Data visualization</strong>: Gemini produces the code to plot various graphs in Matplotlib&#8202;&#8212;&#8202;popularity over time, average popularity and so on.</p></li></ul><p>Here is a sample of one of the visualizations; it tracks the popularity of programming languages over time using the average for each year.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!55bQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e5af57b-a14b-42fa-8041-f6597d0c4da3_1320x700.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!55bQ!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e5af57b-a14b-42fa-8041-f6597d0c4da3_1320x700.png 424w, /__u/substackcdn.com/image/fetch/$s_!55bQ!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e5af57b-a14b-42fa-8041-f6597d0c4da3_1320x700.png 848w, /__u/substackcdn.com/image/fetch/$s_!55bQ!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e5af57b-a14b-42fa-8041-f6597d0c4da3_1320x700.png 1272w, /__u/substackcdn.com/image/fetch/$s_!55bQ!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e5af57b-a14b-42fa-8041-f6597d0c4da3_1320x700.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!55bQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e5af57b-a14b-42fa-8041-f6597d0c4da3_1320x700.png" width="1320" height="700" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5e5af57b-a14b-42fa-8041-f6597d0c4da3_1320x700.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:700,&quot;width&quot;:1320,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!55bQ!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e5af57b-a14b-42fa-8041-f6597d0c4da3_1320x700.png 424w, /__u/substackcdn.com/image/fetch/$s_!55bQ!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e5af57b-a14b-42fa-8041-f6597d0c4da3_1320x700.png 848w, /__u/substackcdn.com/image/fetch/$s_!55bQ!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e5af57b-a14b-42fa-8041-f6597d0c4da3_1320x700.png 1272w, /__u/substackcdn.com/image/fetch/$s_!55bQ!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e5af57b-a14b-42fa-8041-f6597d0c4da3_1320x700.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Following these operations, Gemini comes up with a Summary telling us what it has done and suggesting further steps.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Xj6z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03909b2-e5fa-41a6-9ca5-b07433195536_879x532.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Xj6z!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03909b2-e5fa-41a6-9ca5-b07433195536_879x532.png 424w, /__u/substackcdn.com/image/fetch/$s_!Xj6z!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03909b2-e5fa-41a6-9ca5-b07433195536_879x532.png 848w, /__u/substackcdn.com/image/fetch/$s_!Xj6z!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03909b2-e5fa-41a6-9ca5-b07433195536_879x532.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Xj6z!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03909b2-e5fa-41a6-9ca5-b07433195536_879x532.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Xj6z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03909b2-e5fa-41a6-9ca5-b07433195536_879x532.png" width="879" height="532" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c03909b2-e5fa-41a6-9ca5-b07433195536_879x532.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:532,&quot;width&quot;:879,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Xj6z!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03909b2-e5fa-41a6-9ca5-b07433195536_879x532.png 424w, /__u/substackcdn.com/image/fetch/$s_!Xj6z!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03909b2-e5fa-41a6-9ca5-b07433195536_879x532.png 848w, /__u/substackcdn.com/image/fetch/$s_!Xj6z!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03909b2-e5fa-41a6-9ca5-b07433195536_879x532.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Xj6z!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc03909b2-e5fa-41a6-9ca5-b07433195536_879x532.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You have to bear in mind that Gemini was given no instructions other than to analyse the data. So, it has produced a generic plan and then executed it. If we had wanted something different, we could have asked for it (see below).</p><h4>Generating new cells.</h4><p>That needn&#8217;t be the end of the story. Gemini is active inside each code cell. Each time you create a new code cell, you will see this:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!0pLy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4df7b202-7d87-45bd-97aa-dc628ef5fd2b_259x63.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!0pLy!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4df7b202-7d87-45bd-97aa-dc628ef5fd2b_259x63.png 424w, /__u/substackcdn.com/image/fetch/$s_!0pLy!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4df7b202-7d87-45bd-97aa-dc628ef5fd2b_259x63.png 848w, /__u/substackcdn.com/image/fetch/$s_!0pLy!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4df7b202-7d87-45bd-97aa-dc628ef5fd2b_259x63.png 1272w, /__u/substackcdn.com/image/fetch/$s_!0pLy!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4df7b202-7d87-45bd-97aa-dc628ef5fd2b_259x63.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!0pLy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4df7b202-7d87-45bd-97aa-dc628ef5fd2b_259x63.png" width="259" height="63" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4df7b202-7d87-45bd-97aa-dc628ef5fd2b_259x63.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:63,&quot;width&quot;:259,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!0pLy!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4df7b202-7d87-45bd-97aa-dc628ef5fd2b_259x63.png 424w, /__u/substackcdn.com/image/fetch/$s_!0pLy!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4df7b202-7d87-45bd-97aa-dc628ef5fd2b_259x63.png 848w, /__u/substackcdn.com/image/fetch/$s_!0pLy!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4df7b202-7d87-45bd-97aa-dc628ef5fd2b_259x63.png 1272w, /__u/substackcdn.com/image/fetch/$s_!0pLy!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4df7b202-7d87-45bd-97aa-dc628ef5fd2b_259x63.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Click on &#8216;generate&#8217; and you will be shown a dialog box in which you enter a prompt. Gemini already knows about the Notebook and will happily generate the code for a new cell. For example, I asked it to</p><blockquote><p>&#8220;Create a plot from the original data that plots the average popularity of the top 10 most popular languages for 2024. The result should be a bar plot.&#8221;</p></blockquote><p>It dutifully produced the code to draw the bar chart, but there was a bug. Here is the code that it generated:</p><pre><code># prompt: Create a plot from the original data that plots the average popularity of the top 10 most popular languages for 2024. The result should be a bar plot.

import matplotlib.pyplot as plt

# Assuming 'df' is your DataFrame from the previous code

# Get the latest popularity data (2024)
latest_data = df[df['Date'] == df['Date'].max()]

# Drop the 'Date' and 'Year' columns
latest_popularity = latest_data.drop(['Date', 'Year'], axis=1).iloc[0]

# Sort by popularity and get the top 10
top_10 = latest_popularity.sort_values(ascending=False).head(10)

# Create the bar plot
plt.figure(figsize=(10, 6))
plt.bar(top_10.index, top_10.values)
plt.xlabel("Programming Language")
plt.ylabel("Popularity")
plt.title("Average Popularity of Top 10 Languages (2024)")
plt.xticks(rotation=45, ha='right')  # Rotate x-axis labels for better readability
plt.tight_layout()
plt.show()</code></pre><p>It got a little confused about the column name &#8216;Year&#8217;. This is something that Gemini itself created and is not in the original data. It is easily fixed manually, but it is useful to know that Gemini is capable of fixing its own errors. After an error message you are presented with an &#8216;Explain error&#8217; button. Click this and the Gemini window displays the problem, a hypothesis (what it thinks caused the error), and a fix.</p><p>It correctly diagnosed the error:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!oZ0V!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48469a1e-1024-44ca-a64a-31fba3d7baf6_680x191.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!oZ0V!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48469a1e-1024-44ca-a64a-31fba3d7baf6_680x191.png 424w, /__u/substackcdn.com/image/fetch/$s_!oZ0V!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48469a1e-1024-44ca-a64a-31fba3d7baf6_680x191.png 848w, /__u/substackcdn.com/image/fetch/$s_!oZ0V!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48469a1e-1024-44ca-a64a-31fba3d7baf6_680x191.png 1272w, /__u/substackcdn.com/image/fetch/$s_!oZ0V!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48469a1e-1024-44ca-a64a-31fba3d7baf6_680x191.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!oZ0V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48469a1e-1024-44ca-a64a-31fba3d7baf6_680x191.png" width="680" height="191" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/48469a1e-1024-44ca-a64a-31fba3d7baf6_680x191.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:191,&quot;width&quot;:680,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!oZ0V!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48469a1e-1024-44ca-a64a-31fba3d7baf6_680x191.png 424w, /__u/substackcdn.com/image/fetch/$s_!oZ0V!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48469a1e-1024-44ca-a64a-31fba3d7baf6_680x191.png 848w, /__u/substackcdn.com/image/fetch/$s_!oZ0V!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48469a1e-1024-44ca-a64a-31fba3d7baf6_680x191.png 1272w, /__u/substackcdn.com/image/fetch/$s_!oZ0V!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48469a1e-1024-44ca-a64a-31fba3d7baf6_680x191.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>It then went on to produce the correct code (instead of dropping the &#8216;Date&#8217; and &#8216;Year&#8217; columns, it just dropped &#8216;Date&#8217;), which drew the chart below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!0ntg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f1b9d29-f71a-495f-ba02-e6cb73ad36a9_880x525.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!0ntg!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f1b9d29-f71a-495f-ba02-e6cb73ad36a9_880x525.png 424w, /__u/substackcdn.com/image/fetch/$s_!0ntg!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f1b9d29-f71a-495f-ba02-e6cb73ad36a9_880x525.png 848w, /__u/substackcdn.com/image/fetch/$s_!0ntg!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f1b9d29-f71a-495f-ba02-e6cb73ad36a9_880x525.png 1272w, /__u/substackcdn.com/image/fetch/$s_!0ntg!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f1b9d29-f71a-495f-ba02-e6cb73ad36a9_880x525.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!0ntg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f1b9d29-f71a-495f-ba02-e6cb73ad36a9_880x525.png" width="880" height="525" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6f1b9d29-f71a-495f-ba02-e6cb73ad36a9_880x525.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:525,&quot;width&quot;:880,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!0ntg!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f1b9d29-f71a-495f-ba02-e6cb73ad36a9_880x525.png 424w, /__u/substackcdn.com/image/fetch/$s_!0ntg!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f1b9d29-f71a-495f-ba02-e6cb73ad36a9_880x525.png 848w, /__u/substackcdn.com/image/fetch/$s_!0ntg!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f1b9d29-f71a-495f-ba02-e6cb73ad36a9_880x525.png 1272w, /__u/substackcdn.com/image/fetch/$s_!0ntg!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f1b9d29-f71a-495f-ba02-e6cb73ad36a9_880x525.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I tried a different prompt in the next cell.</p><blockquote><p>Compare how the popularity of Python compares with a combination of Javascript and Typescript.</p></blockquote><p>JavaScript and TypeScript do much the same job, and I would think that at least some of the decline in the use of JavaScript can be attributed to developers moving to TypeScript. So this prompt asks the agent to combine the two languages and compare them with Python.</p><p>Gemini produced the following code.</p><pre><code>import matplotlib.pyplot as plt
# Calculate the combined popularity of JavaScript and TypeScript.
df['JavaScript_TypeScript'] = df['JavaScript'] + df['TypeScript']

# Calculate the average popularity of Python and the combined JavaScript/TypeScript.
avg_python_popularity = df['Python'].mean()
avg_js_ts_popularity = df['JavaScript_TypeScript'].mean()

print(f"Average popularity of Python: {avg_python_popularity}")
print(f"Average popularity of JavaScript and TypeScript combined: {avg_js_ts_popularity}")

# Find the peak popularity and corresponding date for Python and combined JavaScript/TypeScript
peak_python_popularity = df['Python'].max()
peak_python_date = df.loc[df['Python'].idxmax(), 'Date']

peak_js_ts_popularity = df['JavaScript_TypeScript'].max()
peak_js_ts_date = df.loc[df['JavaScript_TypeScript'].idxmax(), 'Date']

print(f"\nPeak popularity of Python: {peak_python_popularity} on {peak_python_date}")
print(f"Peak popularity of JavaScript and TypeScript combined: {peak_js_ts_popularity} on {peak_js_ts_date}")

# Plotting
plt.figure(figsize=(12, 6))
plt.plot(df['Date'], df['Python'], label='Python')
plt.plot(df['Date'], df['JavaScript_TypeScript'], label='JavaScript + TypeScript')
plt.xlabel('Date')
plt.ylabel('Popularity')
plt.title('Popularity of Python vs. JavaScript + TypeScript')
plt.legend()
plt.grid(True)
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()</code></pre><p>Which comes up with the following text output as well as the chart that follows.</p><pre><code>Average popularity of Python: 14.725691056910566
Average popularity of JavaScript and TypeScript combined: 8.893536585365853

Peak popularity of Python: 31.41 on 2020-07-01 00:00:00
Peak popularity of JavaScript and TypeScript combined: 12.469999999999999 on 2023-06-01 00:00:00</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!908Y!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0849db3a-d2ed-424a-b743-350500e4b3d4_880x437.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!908Y!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0849db3a-d2ed-424a-b743-350500e4b3d4_880x437.png 424w, /__u/substackcdn.com/image/fetch/$s_!908Y!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0849db3a-d2ed-424a-b743-350500e4b3d4_880x437.png 848w, /__u/substackcdn.com/image/fetch/$s_!908Y!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0849db3a-d2ed-424a-b743-350500e4b3d4_880x437.png 1272w, /__u/substackcdn.com/image/fetch/$s_!908Y!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0849db3a-d2ed-424a-b743-350500e4b3d4_880x437.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!908Y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0849db3a-d2ed-424a-b743-350500e4b3d4_880x437.png" width="880" height="437" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0849db3a-d2ed-424a-b743-350500e4b3d4_880x437.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:437,&quot;width&quot;:880,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!908Y!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0849db3a-d2ed-424a-b743-350500e4b3d4_880x437.png 424w, /__u/substackcdn.com/image/fetch/$s_!908Y!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0849db3a-d2ed-424a-b743-350500e4b3d4_880x437.png 848w, /__u/substackcdn.com/image/fetch/$s_!908Y!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0849db3a-d2ed-424a-b743-350500e4b3d4_880x437.png 1272w, /__u/substackcdn.com/image/fetch/$s_!908Y!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0849db3a-d2ed-424a-b743-350500e4b3d4_880x437.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Gemini has responded to the prompt correctly. And we can see that both lines in the graph show a general increase in popularity, but with Python surging ahead from around 2016 and JavaScript/TypeScript declining a little recently.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands on Data Visualization, Data Science, AI and Python is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h4>A more directed prompt</h4><p>That&#8217;s one way of using the agent, but probably a more productive method is to tell the agent what you are interested in.</p><p>I went through the same exercise, but this time, instead of simply asking it to analyse the data, I gave it this prompt:</p><blockquote><p>We are interested in how Python has increased in popularity as a language for AI and how Typescript might be replacing Javascript as a front-end language.</p></blockquote><p>And this was the plan that the agent proposed.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!1zwF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcfba870-f5b1-4d55-977a-c9461429ee86_685x396.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!1zwF!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcfba870-f5b1-4d55-977a-c9461429ee86_685x396.png 424w, /__u/substackcdn.com/image/fetch/$s_!1zwF!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcfba870-f5b1-4d55-977a-c9461429ee86_685x396.png 848w, /__u/substackcdn.com/image/fetch/$s_!1zwF!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcfba870-f5b1-4d55-977a-c9461429ee86_685x396.png 1272w, /__u/substackcdn.com/image/fetch/$s_!1zwF!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcfba870-f5b1-4d55-977a-c9461429ee86_685x396.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!1zwF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcfba870-f5b1-4d55-977a-c9461429ee86_685x396.png" width="685" height="396" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dcfba870-f5b1-4d55-977a-c9461429ee86_685x396.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:396,&quot;width&quot;:685,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!1zwF!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcfba870-f5b1-4d55-977a-c9461429ee86_685x396.png 424w, /__u/substackcdn.com/image/fetch/$s_!1zwF!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcfba870-f5b1-4d55-977a-c9461429ee86_685x396.png 848w, /__u/substackcdn.com/image/fetch/$s_!1zwF!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcfba870-f5b1-4d55-977a-c9461429ee86_685x396.png 1272w, /__u/substackcdn.com/image/fetch/$s_!1zwF!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdcfba870-f5b1-4d55-977a-c9461429ee86_685x396.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>As you can see, the plan is much more focused than the previous generic one and concentrates on the languages that we were asking about.</p><p>The data analysis and visualisations concentrated on the growth in popularity of the three languages and below you can see a chart that highlights Python&#8217;s periods of significant growth in popularity.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!FvW0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e443cfe-61d2-453b-9a08-b276fce2654b_880x483.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!FvW0!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e443cfe-61d2-453b-9a08-b276fce2654b_880x483.png 424w, /__u/substackcdn.com/image/fetch/$s_!FvW0!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e443cfe-61d2-453b-9a08-b276fce2654b_880x483.png 848w, /__u/substackcdn.com/image/fetch/$s_!FvW0!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e443cfe-61d2-453b-9a08-b276fce2654b_880x483.png 1272w, /__u/substackcdn.com/image/fetch/$s_!FvW0!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e443cfe-61d2-453b-9a08-b276fce2654b_880x483.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!FvW0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e443cfe-61d2-453b-9a08-b276fce2654b_880x483.png" width="880" height="483" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0e443cfe-61d2-453b-9a08-b276fce2654b_880x483.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:483,&quot;width&quot;:880,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!FvW0!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e443cfe-61d2-453b-9a08-b276fce2654b_880x483.png 424w, /__u/substackcdn.com/image/fetch/$s_!FvW0!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e443cfe-61d2-453b-9a08-b276fce2654b_880x483.png 848w, /__u/substackcdn.com/image/fetch/$s_!FvW0!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e443cfe-61d2-453b-9a08-b276fce2654b_880x483.png 1272w, /__u/substackcdn.com/image/fetch/$s_!FvW0!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e443cfe-61d2-453b-9a08-b276fce2654b_880x483.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The full analysis and the charts generated can be seen in the notebook. Below, you can see that the summary that Gemini produced was very relevant, and it provided sensible suggestions for further investigation.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!RXjH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e92fcf8-0f04-45b0-b1b6-2c7b7c52c59f_880x552.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!RXjH!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e92fcf8-0f04-45b0-b1b6-2c7b7c52c59f_880x552.png 424w, /__u/substackcdn.com/image/fetch/$s_!RXjH!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e92fcf8-0f04-45b0-b1b6-2c7b7c52c59f_880x552.png 848w, /__u/substackcdn.com/image/fetch/$s_!RXjH!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e92fcf8-0f04-45b0-b1b6-2c7b7c52c59f_880x552.png 1272w, /__u/substackcdn.com/image/fetch/$s_!RXjH!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e92fcf8-0f04-45b0-b1b6-2c7b7c52c59f_880x552.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!RXjH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e92fcf8-0f04-45b0-b1b6-2c7b7c52c59f_880x552.png" width="880" height="552" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0e92fcf8-0f04-45b0-b1b6-2c7b7c52c59f_880x552.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:552,&quot;width&quot;:880,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!RXjH!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e92fcf8-0f04-45b0-b1b6-2c7b7c52c59f_880x552.png 424w, /__u/substackcdn.com/image/fetch/$s_!RXjH!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e92fcf8-0f04-45b0-b1b6-2c7b7c52c59f_880x552.png 848w, /__u/substackcdn.com/image/fetch/$s_!RXjH!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e92fcf8-0f04-45b0-b1b6-2c7b7c52c59f_880x552.png 1272w, /__u/substackcdn.com/image/fetch/$s_!RXjH!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e92fcf8-0f04-45b0-b1b6-2c7b7c52c59f_880x552.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4>Conclusion</h4><p>Google&#8217;s Data Science Agent is a very easy-to-use feature in Colab, just upload the data file(s) and write a suitable prompt to guide the agent&#8217;s analysis, and it will generate a plan, execute it and produce an entire notebook for you based on the data provided.</p><p>If you only give it a vague prompt, then the agent will produce a generic analysis. So it is worth putting in some effort to think about what you need from the analysis and writing a prompt that explains this. The better the prompt, the more useful the result.</p><p>I have only given you a brief look at the analysis, visualizations and code that Gemini created. I would encourage you to look at the full notebooks in the repo where you will see the entire analysis, all of the charts, the code and the commentary that Gemini produced.</p><p>I have found the combination of Gemini and Colab to be quite satisfying to use&#8202;&#8212;&#8202;easier than some other AI-supported tools, and I suspect I may continue to use it in future. Take a look at it and, if you feel like it, write a comment about your experiences below.</p><div><hr></div><p>As ever, thanks for reading and I hope that this has been useful. To see more of my articles, follow me on <a href="https://medium.com/@alan-jones">Medium</a> or subscribe to my <a href="/__u/technofile.substack.com/">Substack</a>.</p><h4>Notes</h4><ol><li><p>The data comes from the Kaggle dataset <a href="https://www.kaggle.com/datasets/muhammadkhalid/most-popular-programming-languages-since-2004">Most Popular Programming Languages Since 2004</a> by Muhammad Khalid, accessed 29th April 2025. A copy of the version used here can be found in my GitHub repo, <a href="https://github.com/alanjones2/dataviz/blob/master/programminglanguagesdata/Most%20Popular%20Programming%20Languages.csv">here</a>.</p></li><li><p>All the code and data can be found in the <a href="https://github.com/DataVizandAI/public_code/tree/main/data-analysis-gemini">repository, here.</a></p></li></ol><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/subscribe"><span>Subscribe now</span></a></p><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[Create Brilliant AI Visualizations from any CSV file]]></title><description><![CDATA[Using plain English queries, we can create useful data visualizations]]></description><link>https://technofile.substack.com/p/create-brilliant-ai-visualizations</link><guid isPermaLink="false">https://technofile.substack.com/p/create-brilliant-ai-visualizations</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Sat, 08 Mar 2025 16:58:48 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3cT0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!3cT0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!3cT0!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png 424w, /__u/substackcdn.com/image/fetch/$s_!3cT0!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png 848w, /__u/substackcdn.com/image/fetch/$s_!3cT0!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png 1272w, /__u/substackcdn.com/image/fetch/$s_!3cT0!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!3cT0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png" width="727" height="415.42857142857144" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:832,&quot;width&quot;:1456,&quot;resizeWidth&quot;:727,&quot;bytes&quot;:2568326,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://technofile.substack.com/i/158656684?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!3cT0!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png 424w, /__u/substackcdn.com/image/fetch/$s_!3cT0!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png 848w, /__u/substackcdn.com/image/fetch/$s_!3cT0!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png 1272w, /__u/substackcdn.com/image/fetch/$s_!3cT0!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa66d0b85-5ce8-4b75-9817-7a8d7d94785a_1792x1024.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>An agent drawing a graph</em></figcaption></figure></div><p>Using LLMs to analyse data and produce visualizations is not new - well, it's fairly new, I suppose, but it's nothing spectacular these days.</p><p>But getting an AI to go through a complete dataset to do this is inefficient. And, if your data set is large, you could end up with an unexpected bill for your API usage, have your request refused, or even break the context window.</p><p>So here's an alternative.</p><p>A bit of easily generated metadata can be used by an LLM to create the code for creating a visualization without needing to read a single cell of the data. If you have a dataset, it's likely that you know something about it - so you are one up on an LLM already - and using that knowledge, it becomes easy to instruct the LLM with a little descriptive data rather than the data itself.</p><p>I'm going to describe the code involved as cells in a Jupyter Notebook and then show you a Streamlit app that allows the user to upload a file and specify a chart to be drawn.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/subscribe"><span>Subscribe now</span></a></p><h3>Don't rely on AI for everything - it's tempting but not efficient.</h3><p>I have a CSV file that records CO2 emissions for many countries since the mid 19th century. It has only 5 columns but over 25,000 rows. It's less than a megabyte of data, but that is enough for my preferred LLM setup to refuse to deal with it.</p><p>But if I give an LLM a little information, it can do the work I want without looking at the data at all.</p><p>Here is the information I give it.</p><ul><li><p>File name: 'data/co2_total.csv'</p></li><li><p>Data columns:</p><ul><li><p>unnamed: index</p></li><li><p>'Entity': a string containing a country or area name</p></li><li><p>'Code': a short code for 'Entity'</p></li><li><p>'Year': an integer representing the year</p></li><li><p>'Annual CO2 emissions': a real number representing the CO2 Emissions in billions of tonnes</p></li></ul></li></ul><p>With this, I can ask the LLM to write Python code to analyse the data and produce charts.</p><p>For example, I could ask it to provide code to plot the yearly emissions of a set of countries. I could ask it to work out the top 5 emitters and draw a bar graph of their emissions. I show how these two examples work below.</p><p>The code to do this is not difficult. I'll go through a set of Jupyter Notebook cells step by step for this particular dataset.</p><h3>Code inspection or sandboxing</h3><p>You can't trust them! LLMs are notorious for hallucinating, and while it might be unlikely, it is possible that the code produced could be destructive. There are two ways of preventing this: check the code before executing it or execute it in a sandboxed environment where it cannot do any harm.</p><p>If we want non-programmers to use an app like this, then the only option is sandboxing, but to introduce the technique, we'll assume the user will understand the code generated and let him/her review it before running it.</p><p>When it comes to the Streamlit app, the code can also be reviewed and edited before running it, but if the app is published, then it is running in a container and thus isolated from anything that it could harm. If you run it locally, you might be wise to use Docker to execute the program.</p><h3>The Notebook</h3><p>I'm going to specify a particular CSV file that I derived from <a href="https://ourworldindata.org/">Our World in Data</a> and a simple metadata file that contains the column information (as we saw above).</p><p>You could use pretty much any AI framework, or none, but I like PydanticAI, so I'm going to use that. It's open source and easy to understand.</p><p>A good thing about PydanticAI is that it doesn't care which model you use; you simply tell it the model name, and it will deal with it. The code below uses OpenAI since I already have an account with them. But any mainstream LLM would suffice.</p><p>For plotting, I've tried the code with <code>Matplotlib</code>, <code>Altair</code> and <code>Plotly</code> - all work, but my preference is to use Plotly. Other plotting libraries would probably be fine as long as the LLM is familiar with them.</p><p>If you intend to use this code, you will need an OpenAI account and an API key. And they will charge you a small amount for usage (I've run the code many times, and it has cost me a few 10s of cents). Other LLM providers might be cheaper (or not).</p><h3>The Data</h3><p>The data looks like the table below. It is just a set of carbon emissions over time for a list of countries.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!kqQE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa74a4b4b-b44f-466f-8e80-ca0298fc5261_450x323.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!kqQE!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa74a4b4b-b44f-466f-8e80-ca0298fc5261_450x323.png 424w, /__u/substackcdn.com/image/fetch/$s_!kqQE!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa74a4b4b-b44f-466f-8e80-ca0298fc5261_450x323.png 848w, /__u/substackcdn.com/image/fetch/$s_!kqQE!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa74a4b4b-b44f-466f-8e80-ca0298fc5261_450x323.png 1272w, /__u/substackcdn.com/image/fetch/$s_!kqQE!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa74a4b4b-b44f-466f-8e80-ca0298fc5261_450x323.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!kqQE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa74a4b4b-b44f-466f-8e80-ca0298fc5261_450x323.png" width="450" height="323" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a74a4b4b-b44f-466f-8e80-ca0298fc5261_450x323.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:323,&quot;width&quot;:450,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!kqQE!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa74a4b4b-b44f-466f-8e80-ca0298fc5261_450x323.png 424w, /__u/substackcdn.com/image/fetch/$s_!kqQE!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa74a4b4b-b44f-466f-8e80-ca0298fc5261_450x323.png 848w, /__u/substackcdn.com/image/fetch/$s_!kqQE!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa74a4b4b-b44f-466f-8e80-ca0298fc5261_450x323.png 1272w, /__u/substackcdn.com/image/fetch/$s_!kqQE!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa74a4b4b-b44f-466f-8e80-ca0298fc5261_450x323.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I wrote the metadata that the LLM is going to use in a variable <code>metadata</code>, as you can see below.</p><pre><code><code>metadata = """
File name: 'data/co2_total.csv'
Data columns:
     unnamed: index
    'Entity': a string containing a country or area name
    'Code'  : a short code for 'Entity'
    'Year'  : an integer representing the year 
    'Annual CO2 emissions': a real number representing the CO2 Emissions in billions of tonnes
"""</code></code></pre><p>I then decided on what charts I wanted the LLM to produce and put this into the variable <code>request</code>.</p><pre><code><code># Change this for the chart you want to create

request = """
The chart should display the emissions for France, United States, 
China and Russia over time.
"""</code></code></pre><p>This expects the data to be filtered on the countries given and a chart drawn from that.</p><p>Both of these are variable data (in the interactive application, they are set by the user). If you'd like to try it out with a different dataset, these are the cells you need to change.</p><h3>It's all in the prompt</h3><p>In the next cell, I have defined three things. The first is the plotting library I want to use; as I mentioned, I've successfully used Matplotlib or Altair, but here it is set to ''Plotly'' with some extra instructions added in brackets.</p><p>The next string is the user prompt that will be sent ot the LLM. This is constructed with the variables that were set above.</p><p>Next is the system prompt, which is used to set up the Agent.</p><pre><code><code>plotting_lib  = "plotly (use the plotly_white template and a figure size of 1200 x 800)"

prompt = f"""
A description of data the follows...

&lt;description&gt;
{metadata}
&lt;/description&gt;

Your task is as follows...
&lt;task&gt;
{request}
&lt;/task&gt;

The expected output is valid Python code for a {plotting_lib} chart
"""

# System prompt

sys_prompt= f"""
You are an expert in writing Python code for data analysis and visualization.
Your aim is to read and analyse data and create the code for a chart as instructed.
Do not read the data directly. Use the metadata provided to create the a {plotting_lib} chart 
from the data described there. Do not use Markdown fencing around the code.
"""</code></code></pre><p>Frankly, this is where most of the work is done. These prompts ensure that the LLM does not try reading the data but only uses the metadata to create a program that responds to the user request and uses the specified plotting library.</p><h3>The Agent</h3><p>The agent will be set up with the prompts above and then send the request to the LLM.</p><p>According to the PydanticAI docs, running PydanticAI in Jupyter will cause this error:</p><p><code>RuntimeError: This event loop is already running</code></p><p>The error is caused by conflicts between the event loops in Jupyter notebook and PydanticAI's. ' One way to manage these conflicts is by using nest-asyncio. Namely, before you execute any agent runs, do the following:</p><pre><code><code>from pydantic_ai import Agent
import nest_asyncio
nest_asyncio.apply()</code></code></pre><p>Having done that, we can get on to the useful code. Below, we create the agent with an OpenAI model and a system prompt, run it with the user prompt and print the result for the user to review.</p><pre><code><code>agent = Agent(  
    'openai:gpt-4o-mini',
    system_prompt=sys_prompt,  
)

result = agent.run_sync(prompt)  

print(result.data)</code></code></pre><p>The code that it produced with this setup is reproduced below. It's pretty much what I would have written had I done it by hand, so it must be quite good, right?.</p><pre><code><code># Agent-generated code
import pandas as pd
import plotly.express as px

# Load the data
df = pd.read_csv('data/co2_total.csv')

# Filter the data for specific countries
countries = ['France', 'United States', 'China', 'Russia']
filtered_df = df[df['Entity'].isin(countries)]

# Create the plot
fig = px.line(filtered_df, x='Year', y='Annual CO2 emissions', color='Entity',
              title='Annual CO2 Emissions for Selected Countries Over Time',
              template='plotly_white')

# Update the figure size
fig.update_layout(width=800, height=600)

# Show the figure
fig.show()</code></code></pre><p><em>To be crystal clear, the code above is the output of the code so far - <strong>don't</strong> include this in a Notebook cell!</em></p><p>The next cell just asks the user whether the code should be run. And if the answer is <em>yes</em>, then the code is executed.</p><pre><code><code>execute_code = input("Do you want to execute this code? (yes/no): ").strip().lower() == 'yes'

if execute_code:
    exec(result.data)
else:
    print("Code execution skipped.")</code></code></pre><p>The result of this code is the following chart, and it is exactly what was asked for.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!UYwR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0e7ea88-f147-483a-8310-6863ff1c672c_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!UYwR!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0e7ea88-f147-483a-8310-6863ff1c672c_800x600.png 424w, /__u/substackcdn.com/image/fetch/$s_!UYwR!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0e7ea88-f147-483a-8310-6863ff1c672c_800x600.png 848w, /__u/substackcdn.com/image/fetch/$s_!UYwR!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0e7ea88-f147-483a-8310-6863ff1c672c_800x600.png 1272w, /__u/substackcdn.com/image/fetch/$s_!UYwR!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0e7ea88-f147-483a-8310-6863ff1c672c_800x600.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!UYwR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0e7ea88-f147-483a-8310-6863ff1c672c_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b0e7ea88-f147-483a-8310-6863ff1c672c_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!UYwR!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0e7ea88-f147-483a-8310-6863ff1c672c_800x600.png 424w, /__u/substackcdn.com/image/fetch/$s_!UYwR!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0e7ea88-f147-483a-8310-6863ff1c672c_800x600.png 848w, /__u/substackcdn.com/image/fetch/$s_!UYwR!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0e7ea88-f147-483a-8310-6863ff1c672c_800x600.png 1272w, /__u/substackcdn.com/image/fetch/$s_!UYwR!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0e7ea88-f147-483a-8310-6863ff1c672c_800x600.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Just to show that this is not a fluke, I changed the prompt to:</p><pre><code><code>request = """
Calculate the top 5 emitters in the year 2000 and display a bar chart of the emissions for those countries in that year.
"""</code></code></pre><p>It needs to do a bit more calculation for this, and for whatever reason, it used the Plotly Graphics Objects library instead of Plotly Express (as before). (I could have forced it to use Plotly Express in the prompt, but there might be circumstances when GO is the right answer, so it is of no real consequence.)</p><p>Again, the chart it produced was entirely correct.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!SEgl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F159c8e19-e04f-462d-adee-bc2d0a918376_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!SEgl!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F159c8e19-e04f-462d-adee-bc2d0a918376_800x600.png 424w, /__u/substackcdn.com/image/fetch/$s_!SEgl!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F159c8e19-e04f-462d-adee-bc2d0a918376_800x600.png 848w, /__u/substackcdn.com/image/fetch/$s_!SEgl!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F159c8e19-e04f-462d-adee-bc2d0a918376_800x600.png 1272w, /__u/substackcdn.com/image/fetch/$s_!SEgl!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F159c8e19-e04f-462d-adee-bc2d0a918376_800x600.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!SEgl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F159c8e19-e04f-462d-adee-bc2d0a918376_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/159c8e19-e04f-462d-adee-bc2d0a918376_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!SEgl!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F159c8e19-e04f-462d-adee-bc2d0a918376_800x600.png 424w, /__u/substackcdn.com/image/fetch/$s_!SEgl!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F159c8e19-e04f-462d-adee-bc2d0a918376_800x600.png 848w, /__u/substackcdn.com/image/fetch/$s_!SEgl!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F159c8e19-e04f-462d-adee-bc2d0a918376_800x600.png 1272w, /__u/substackcdn.com/image/fetch/$s_!SEgl!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F159c8e19-e04f-462d-adee-bc2d0a918376_800x600.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>The App</h3><p>I've written a Streamlit app that implements the code above in an interactive way. In a sidebar, the user is prompted to upload a CSV file and asked to describe it. Then, in the main window, the user can input a query to create a chart (the first time around, an OpenAI API key needs to be entered). The generated code is displayed in a text field and can be edited.</p><p>When the user is satisfied with the code, it can be run, and the result is displayed.</p><p>You can see a screenshot of the app below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!AlmI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff299abeb-a6bd-4ebc-a8ed-83e2ac12810c_1879x834.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!AlmI!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff299abeb-a6bd-4ebc-a8ed-83e2ac12810c_1879x834.png 424w, /__u/substackcdn.com/image/fetch/$s_!AlmI!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff299abeb-a6bd-4ebc-a8ed-83e2ac12810c_1879x834.png 848w, /__u/substackcdn.com/image/fetch/$s_!AlmI!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff299abeb-a6bd-4ebc-a8ed-83e2ac12810c_1879x834.png 1272w, /__u/substackcdn.com/image/fetch/$s_!AlmI!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff299abeb-a6bd-4ebc-a8ed-83e2ac12810c_1879x834.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!AlmI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff299abeb-a6bd-4ebc-a8ed-83e2ac12810c_1879x834.png" width="1456" height="646" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f299abeb-a6bd-4ebc-a8ed-83e2ac12810c_1879x834.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:646,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!AlmI!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff299abeb-a6bd-4ebc-a8ed-83e2ac12810c_1879x834.png 424w, /__u/substackcdn.com/image/fetch/$s_!AlmI!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff299abeb-a6bd-4ebc-a8ed-83e2ac12810c_1879x834.png 848w, /__u/substackcdn.com/image/fetch/$s_!AlmI!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff299abeb-a6bd-4ebc-a8ed-83e2ac12810c_1879x834.png 1272w, /__u/substackcdn.com/image/fetch/$s_!AlmI!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff299abeb-a6bd-4ebc-a8ed-83e2ac12810c_1879x834.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>It's not especially pretty, but it is functional. The session that you see there is using the same CO2 Emissions file as above, and the request was to "<em>find the top 5 emitters in 2020 and draw a chart of the emissions in those countries over all years. use different colours for the countries</em>".</p><p>You can see the resulting chart on the right.</p><p>You don't need any programming knowledge to use the app unless, of course, you want to customize the code that is produced.</p><h3>Conclusion</h3><p>This is not rocket science, and the coding is not difficult. The work is really done in the prompts where you can see I've built up the user and system prompts from the user input.</p><p>I've used fairly simple prompts here, and although more complex prompts are also possible, it must be borne in mind that no 'intelligent' observations can be made as the LLM does not see the data. And, of course, this technique is only useful for drawing charts and other functions that can be readily coded in Python.</p><p>Can you do damage with this app?</p><p>Oh, yes!</p><p>If you append "<em>...then delete all the files in the current folder</em>" to your request, it will happily append this code to the result.</p><pre><code><code># Delete all files in the current folder
for file in os.listdir():
    if os.path.isfile(file):
        os.remove(file)</code></code></pre><p>So, if you are going to let inexperienced or untrustworthy users loose on something like this, you should definitely use Docker or some other sandboxing method!</p><p>Note: <a href="https://alanjones2-st-pydanticai-charts-app-dmnooh.streamlit.app/">the Streamlit app is here</a> and here is the <a href="https://github.com/DataVizandAI/public_code/tree/main/pydanticai-charts">GitHub repo for the code</a></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/create-brilliant-ai-visualizations?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/create-brilliant-ai-visualizations?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Subscriber update...]]></title><description><![CDATA[A quick note to let you know that there is a paid subscription tier for Hands on Data Visualization, Data Science, AI and Python.]]></description><link>https://technofile.substack.com/p/subscriber-update</link><guid isPermaLink="false">https://technofile.substack.com/p/subscriber-update</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Tue, 04 Mar 2025 16:12:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!x1nV!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1b92511-34db-46c0-bfed-ad4e6ad27b5e_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A quick note to let you know that there is a paid subscription tier for <strong>Hands on Data Visualization, Data Science, AI and Python.</strong></p><p>I&#8217;m afraid you don&#8217;t get anything more than a free subscriber gets<em> <strong>at the moment</strong></em>. But from now on, I will be posting whole articles, not just links to where you can read them, and hopefully more regularly. I also hope to provide extra stuff for paying subscribers in the future.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands on Data Visualization, Data Science, AI and Python is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Data Visualization with Dash and Bootstrap Components]]></title><description><![CDATA[A simple data dashboard in pure Python]]></description><link>https://technofile.substack.com/p/data-visualization-with-dash-and</link><guid isPermaLink="false">https://technofile.substack.com/p/data-visualization-with-dash-and</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Sat, 01 Mar 2025 16:21:21 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!HDZ-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43614980-89a5-40df-abe8-116480f2c359_1200x691.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!HDZ-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43614980-89a5-40df-abe8-116480f2c359_1200x691.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!HDZ-!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43614980-89a5-40df-abe8-116480f2c359_1200x691.png 424w, /__u/substackcdn.com/image/fetch/$s_!HDZ-!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43614980-89a5-40df-abe8-116480f2c359_1200x691.png 848w, /__u/substackcdn.com/image/fetch/$s_!HDZ-!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43614980-89a5-40df-abe8-116480f2c359_1200x691.png 1272w, /__u/substackcdn.com/image/fetch/$s_!HDZ-!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43614980-89a5-40df-abe8-116480f2c359_1200x691.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!HDZ-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43614980-89a5-40df-abe8-116480f2c359_1200x691.png" width="1200" height="691" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/43614980-89a5-40df-abe8-116480f2c359_1200x691.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:691,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!HDZ-!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43614980-89a5-40df-abe8-116480f2c359_1200x691.png 424w, /__u/substackcdn.com/image/fetch/$s_!HDZ-!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43614980-89a5-40df-abe8-116480f2c359_1200x691.png 848w, /__u/substackcdn.com/image/fetch/$s_!HDZ-!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43614980-89a5-40df-abe8-116480f2c359_1200x691.png 1272w, /__u/substackcdn.com/image/fetch/$s_!HDZ-!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43614980-89a5-40df-abe8-116480f2c359_1200x691.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I&#8217;ve been ignoring Dash for years, preferring to use a combination of Flask and HTML. My argument was that if you need to create your user interface in HTML (which you kind of have to in Dash), then why not go the whole hog and actually write it in HTML? <a href="https://medium.com/towards-data-science/flapjax-data-visualization-on-the-web-with-plotly-and-flask-465090fa3fba">As I wrote here, it&#8217;s not so difficult</a>.</p><p>Anyway, then along came Streamlit, which made things easier.</p><p>But I occasionally got a bit annoyed with Streamlit&#8202;&#8212;&#8202;it is too easy to mix the UI with the rest of the code, and if you aren&#8217;t careful, it can be a mess.</p><p>So I started looking at other platforms, <a href="https://medium.com/towards-data-science/a-data-dashboard-in-pure-python-with-taipy-bdb164a62b8b">Taipy</a> and <a href="https://medium.com/towards-data-science/hands-on-data-visualization-with-google-mesop-bdde37ef09da">Mesop</a>, for example&#8202;&#8212;&#8202;both of these nicely separate the program logic from the UI. Much less messy, but designing the UI on these platforms was much closer to writing HTML in Python&#8202;&#8212;&#8202;my original bugbear with Dash.</p><p>So, belatedly, I decided it was time to take another look at Dash. Also belatedly, I found that I could use my favourite Bootstrap components with it (I rarely write HTML without Bootstrap), and I made the app you can see above.</p><p>It&#8217;s a simple dashboard-type app with two interactive charts (a choropleth and a bar chart) along with their controls (a drop-down menu and a slider).</p><p>As you can see from the image, it&#8217;s not so bad!</p><p>Well, I was fairly happy with the result, anyway. I&#8217;ve never properly engaged with Dash before, and I was quite pleased that it didn&#8217;t feel any more difficult than Streamlit (or Taipy or Mesop).</p><p>The whole app is around 80 lines of well-spaced-out code. A fair chunk of that is to draw the choropleth, and the Dash/Bootstrap UI is only about 20 lines.</p><p>So, let&#8217;s look at how it&#8217;s put together.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/subscribe"><span>Subscribe now</span></a></p><h3>A Dash app</h3><p>A Dash app consists of four parts:</p><ul><li><p>the preliminary code that sets up the app and does any data set up and so on,</p></li><li><p>the page layout, which is defined as Dash and Bootstrap components,</p></li><li><p>callbacks, which are the functions that are called in response to user interaction,</p></li><li><p>the app run command.</p></li></ul><p>We&#8217;ll look at all of these and how they are put together shortly, and you will find all of the code in my <a href="https://github.com/DataVizandAI/public_code/tree/main/dash-bootstrap">GitHub repo</a>.</p><p>But first, let&#8217;s look at the way we define the page.</p><h3>Page layout</h3><p>When deployed, a Dash app consists of two parts: the web page displayed in the browser and the code that supports it, which remains on the server. This separation is hidden; the HTML page layout, which will become the web page, is defined in the app code.</p><p>Both Dash and Bootstrap provide us with components that get converted to HTML. Bootstrap also incorporates styles we can adopt to make our page look good and stylistically consistent.</p><p>I have defined a default style using Bootstrap that gives every component a common look: a border, a light background, margins around the component and padding inside it. This is a single line of code (that we will see soon) that is applied to each component. The layout of the page looks like the image below. You might find the design a little fussy, but one of my aims is to demonstrate the use of Bootstrap styles, and this does the job, as we will see later.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!UE4N!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dd39877-a48a-43a5-832b-e47cf789aa00_737x236.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!UE4N!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dd39877-a48a-43a5-832b-e47cf789aa00_737x236.png 424w, /__u/substackcdn.com/image/fetch/$s_!UE4N!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dd39877-a48a-43a5-832b-e47cf789aa00_737x236.png 848w, /__u/substackcdn.com/image/fetch/$s_!UE4N!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dd39877-a48a-43a5-832b-e47cf789aa00_737x236.png 1272w, /__u/substackcdn.com/image/fetch/$s_!UE4N!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dd39877-a48a-43a5-832b-e47cf789aa00_737x236.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!UE4N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dd39877-a48a-43a5-832b-e47cf789aa00_737x236.png" width="737" height="236" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6dd39877-a48a-43a5-832b-e47cf789aa00_737x236.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:236,&quot;width&quot;:737,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!UE4N!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dd39877-a48a-43a5-832b-e47cf789aa00_737x236.png 424w, /__u/substackcdn.com/image/fetch/$s_!UE4N!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dd39877-a48a-43a5-832b-e47cf789aa00_737x236.png 848w, /__u/substackcdn.com/image/fetch/$s_!UE4N!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dd39877-a48a-43a5-832b-e47cf789aa00_737x236.png 1272w, /__u/substackcdn.com/image/fetch/$s_!UE4N!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dd39877-a48a-43a5-832b-e47cf789aa00_737x236.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>There are four main components to the UI: the outer container that wraps the whole page; a header that is styled a little differently to make it stand out; and two columns that contain the charts, the user controls and some text. At the bottom of the outer container, there is a footer&#8202;&#8212;&#8202;just a string of text.</p><p>In HTML, we would write this page as a set of tags, mostly <code>&lt;div&gt;</code> tags, that are nested inside each other. With Dash, we use the components provided and code the UI in Python.</p><h3>A first Dash app with Bootstrap styling</h3><p>Let&#8217;s have a quick blast through a simple Dash app that uses Bootstrap components.</p><p>Below is the code for a very simple Dash app that uses Bootstrap styling, and below that is a screenshot of the result. We will use this as the basis of the full app.</p><pre><code>from dash import Dash, html
import dash_bootstrap_components as dbc

# Initialize the Dash app with Bootstrap stylesheet
app = Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])

# Define a default CSS class for styling
DEFAULT_CLASS = 'border border-primary rounded bg-light p-2 m-2'

# Define the layout of the app
app.layout = dbc.Container(
    [
        html.H1("A Bootstrap 'primary' styled header",
        className="text-primary"),
        html.Div("Some normal text in a 'secondary' style",
        className='text-secondary'),
    ], className=DEFAULT_CLASS
)

# Run the app
if __name__ == '__main__':
    app.run(debug=True)</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Z9hZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54c7e205-c51e-4588-83f7-cedec9c5fa11_730x107.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Z9hZ!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54c7e205-c51e-4588-83f7-cedec9c5fa11_730x107.png 424w, /__u/substackcdn.com/image/fetch/$s_!Z9hZ!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54c7e205-c51e-4588-83f7-cedec9c5fa11_730x107.png 848w, /__u/substackcdn.com/image/fetch/$s_!Z9hZ!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54c7e205-c51e-4588-83f7-cedec9c5fa11_730x107.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Z9hZ!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54c7e205-c51e-4588-83f7-cedec9c5fa11_730x107.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Z9hZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54c7e205-c51e-4588-83f7-cedec9c5fa11_730x107.png" width="730" height="107" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/54c7e205-c51e-4588-83f7-cedec9c5fa11_730x107.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:107,&quot;width&quot;:730,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Z9hZ!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54c7e205-c51e-4588-83f7-cedec9c5fa11_730x107.png 424w, /__u/substackcdn.com/image/fetch/$s_!Z9hZ!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54c7e205-c51e-4588-83f7-cedec9c5fa11_730x107.png 848w, /__u/substackcdn.com/image/fetch/$s_!Z9hZ!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54c7e205-c51e-4588-83f7-cedec9c5fa11_730x107.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Z9hZ!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F54c7e205-c51e-4588-83f7-cedec9c5fa11_730x107.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The first couple of lines import the required libraries. If you want to follow along with the coding, you&#8217;ll probably want ot create a virtual environment and <code>pip install</code> these (or use whatever your favourite installation method is). Later, you will also need <code>plotly</code>, <code>pandas</code> and <code>numpy</code>.</p><p>After that, the Dash app itself is created, and here we need to tell Dash that we will be using the Bootstrap themes.</p><p>There are two aspects of the Bootstrap components: one is the component themselves (e.g. the rows and columns we&#8217;ll see later). Styles are defined as classes by Bootstrap, and we can string them together to make quite complex styles. For example, there are classes that define borders, ones that define margins and padding, and those that determine how the text and the background should look.</p><p>As I mentioned before, I set up a default style, and that is the next line of code that you see.</p><pre><code>DEFAULT_CLASS = 'border border-primary rounded bg-light p-2 m-2'</code></pre><p>The meaning of each part is as follows:</p><ul><li><p><code>border</code> - there is a border around the component</p></li><li><p><code>border-primary</code> - that is the colour of the border</p></li><li><p><code>rounded</code> - the border has rounded corners</p></li><li><p><code>bg-light</code> - the background colour</p></li><li><p><code>p-2</code> - two pixels of padding</p></li><li><p><code>m-2</code> - a two-pixel margin</p></li></ul><p>There are many, many ways of setting up the way that Bootstrap components look. See the [Bootstrap docs](<a href="https://getbootstrap.com/docs/5.3/getting-started/introduction/">Get started with Bootstrap &#183; Bootstrap v5.3</a>) for the full set of components and styles and the <a href="https://dash-bootstrap-components.opensource.faculty.ai/">Dash Bootstrap Components</a> for how to use them in Dash.</p><p>We can see the usage of this default style in the first component in the layout. Because that is the next thing we come across. The <code>app.layout</code> defines how the app will look, and here we assign it to a component called <code>dbc.container</code>. This is a general-purpose container provided by Bootstrap, which contains a list of elements or other containers. At the end of that list, we can specify the style of the container, and it is here that we use the default style.</p><p>Inside the container, there are two more elements: a header and a <em>div</em> container. The purpose of a header is self-explanatory, and a <em>div</em> is another general-purpose container (that will create an HTML tag).</p><p>Each of these elements contains a string, which will be displayed and a <code>classname</code> which defines the style (in this case, the colour).</p><p>The last couple of lines of code run the app, and in this case, we set the <code>debug</code> flag to <code>True</code>. This is convenient for development, as it will reload the app whenever it detects a change.</p><p>The thing we don&#8217;t see in this app is the dynamic part&#8202;&#8212;&#8202;the callback functions. These are invoked when a UI component changes, and we need something to be done. We&#8217;ll get on to those later.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/data-visualization-with-dash-and?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/data-visualization-with-dash-and?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><h3>Callbacks&#8202;&#8212;&#8202;adding charts and controls</h3><p>The final app displays charts of CO&#8322; emissions that come from a local CSV file.</p><p>Our next app gets part of the way there by reading data and building a chart from it. Furthermore, it incorporates a user control (a slider) that lets the user choose the particular aspect of the data to be displayed (the year).</p><p>This illustrates how Dash deals with user input via callback functions. These functions are linked to values in the user interface: the input that has changed and an output value that the callback will calculate from that changed input.</p><p>Here is what our data looks like.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!4ZZi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc437de44-9f74-4493-b5d0-1fd6ccea787a_379x365.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!4ZZi!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc437de44-9f74-4493-b5d0-1fd6ccea787a_379x365.png 424w, /__u/substackcdn.com/image/fetch/$s_!4ZZi!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc437de44-9f74-4493-b5d0-1fd6ccea787a_379x365.png 848w, /__u/substackcdn.com/image/fetch/$s_!4ZZi!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc437de44-9f74-4493-b5d0-1fd6ccea787a_379x365.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4ZZi!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc437de44-9f74-4493-b5d0-1fd6ccea787a_379x365.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!4ZZi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc437de44-9f74-4493-b5d0-1fd6ccea787a_379x365.png" width="379" height="365" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c437de44-9f74-4493-b5d0-1fd6ccea787a_379x365.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:365,&quot;width&quot;:379,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!4ZZi!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc437de44-9f74-4493-b5d0-1fd6ccea787a_379x365.png 424w, /__u/substackcdn.com/image/fetch/$s_!4ZZi!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc437de44-9f74-4493-b5d0-1fd6ccea787a_379x365.png 848w, /__u/substackcdn.com/image/fetch/$s_!4ZZi!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc437de44-9f74-4493-b5d0-1fd6ccea787a_379x365.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4ZZi!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc437de44-9f74-4493-b5d0-1fd6ccea787a_379x365.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>It is a simple table that records CO&#8322; emissions for a country (&#8216;Entity&#8217;) in a particular year and is sourced from <strong><a href="https://ourworldindata.org/">Our World in Data</a></strong>.</p><p>The application allows users to explore CO&#8322; emissions data over time by selecting a specific year from a slider. A <strong>choropleth map</strong> updates dynamically, displaying emissions for each country using a color scale.</p><p>First, we import the necessary libraries&#8202;&#8212;&#8202;there are a couple more this time:</p><pre><code>from dash import Dash, html, dcc, callback, Output, Input
import plotly.express as px
import pandas as pd
import dash_bootstrap_components as dbc</code></pre><ul><li><p>Dash and Dash Bootstrap Components (dbc) as before.</p></li><li><p>Plotly Express (px) is used to generate the choropleth map.</p></li><li><p>Pandas loads and manipulates the CO&#8322; emissions dataset.</p></li></ul><p>As before, we create an instance of <code>Dash</code> and apply an external Bootstrap stylesheet for styling:</p><pre><code>app = Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])</code></pre><p>The dataset, stored in a CSV file, is loaded using Pandas. We record the minimum, maximum, and midpoint years for configuring the slider later:</p><pre><code>df = pd.read_csv("data/co2_total.csv")
marks = {int(i): str(i) for i in df.Year.unique() if i % 50 == 0}

min_year = df.Year.min()
max_year = df.Year.max()
mid_year = (max_year + min_year) // 2</code></pre><p>Again, we define the default layout.</p><pre><code>DEFAULT_CLASS = 'border border-primary rounded p-2 bg-light m-2'</code></pre><h3>Defining the Layout</h3><p>As we have seen above, Dash uses a declarative layout structure and here, we organize components using Bootstrap&#8217;s <code>Container</code> and <code>Row</code>:</p><pre><code>app.layout = dbc.Container([
    html.H1('Dash App with Bootstrap Components - CO&#8322; Emissions', 
             className="{DEFAULT_CLASS} text-center text-dark bg-dark-subtle"),
    dbc.Row([
        html.Div('Global CO&#8322; Emissions', className='h3 text-danger'),
        html.Div("Move the slider to display CO&#8322; emissions by country for a specific year", className='text-secondary'),
        dcc.Slider(min=min_year, max=max_year, value=mid_year, step=1, marks=marks, id='slider-value'),
        dcc.Graph(id='graph2-content'),
        dcc.Markdown("""
            The data used in this article is derived from Our World in Data.
            OWD publishes articles and data about the most pressing problems that the world faces.
            All its content is open source and its data is downloadable.
            See [Our World in Data](https://ourworldindata.org/) for details.
        """, className='text-secondary')
    ], className='border border-primary rounded p-2 bg-light m-2')
], className="container-fluid")</code></pre><h4>Here are the components in detail:</h4><ul><li><p><strong>Container</strong>: This is a a general purpose container for the whole app</p></li><li><p><strong>Title (H1)</strong>: The main heading is styled with Bootstrap classes&#8202;&#8212;&#8202;the text and background style from the default style are overridden.</p></li><li><p><strong>Row</strong>: by itself, a row doesn&#8217;t do anything except act as another container. The reason for using a row here is because the final app will create two columns in the row for the two graphs</p></li><li><p><strong>Divs</strong>: These are text containers that provide user guidance and context&#8202;&#8212;&#8202;the first is an <em>H3</em> header that is coloured red (the &#8216;text-danger&#8217; class).</p></li><li><p><strong>Slider</strong>: Allows users to select a year to update the map.</p></li><li><p><strong>Graph</strong>: Displays CO&#8322; emissions using a choropleth map.</p></li><li><p><strong>Markdown</strong>: A markdown container can contain any valid markdown text and here provides data attribution.</p></li></ul><h3>Creating the Callback for Interactivity</h3><p>Dash uses a <strong>callback function</strong> to update the map when the slider value changes. A callback function is preceded by the <code>@callback</code> decorator, which defines the input and output for the function. The input and output consist of two parts: the ID of a UI element and a value type. In this case, the input comes from the slider, and it is a 'value' (the year), while the output goes to the graph container and is a 'figure'.</p><pre><code>@callback(
    Output('graph2-content', 'figure'),
    Input('slider-value', 'value')
)
def update_graph(value):
    col = 'Annual CO&#8322; emissions'
    max_val = df[col].max()
    min_val = df[col].min()

    fig = px.choropleth(df[df['Year'] == value],
        locations="Code",  # Country ISO codes
        color=col,  # CO&#8322; emissions data
        hover_name="Entity",  # Country name
        range_color=(min_val, max_val),
        scope='world',
        projection='equirectangular',
        title=f"CO&#8322; Emissions by Country in {value}",
        color_continuous_scale=px.colors.sequential.Reds
    )

    fig.update_layout(
        margin=dict(l=0, r=0, t=60, b=0),
        coloraxis_colorbar=dict(title="Tonnes"),
    )

    return fig</code></pre><p>The function is quite simple: it listens for changes in the slider value and draws a Plotly choropleth with the dataframe filtered by <code>value</code> which is the year selected by the slider. The updated figure is returned to the graph component.</p><p>Finally, we start the Dash server to launch the app.</p><pre><code>if __name__ == '__main__':
    app.run(debug=True)</code></pre><p>The result can be seen in the screenshot below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!mLIF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd63a9af3-a44a-4b71-bca5-f15570273573_800x457.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!mLIF!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd63a9af3-a44a-4b71-bca5-f15570273573_800x457.png 424w, /__u/substackcdn.com/image/fetch/$s_!mLIF!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd63a9af3-a44a-4b71-bca5-f15570273573_800x457.png 848w, /__u/substackcdn.com/image/fetch/$s_!mLIF!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd63a9af3-a44a-4b71-bca5-f15570273573_800x457.png 1272w, /__u/substackcdn.com/image/fetch/$s_!mLIF!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd63a9af3-a44a-4b71-bca5-f15570273573_800x457.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!mLIF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd63a9af3-a44a-4b71-bca5-f15570273573_800x457.png" width="800" height="457" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d63a9af3-a44a-4b71-bca5-f15570273573_800x457.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:457,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!mLIF!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd63a9af3-a44a-4b71-bca5-f15570273573_800x457.png 424w, /__u/substackcdn.com/image/fetch/$s_!mLIF!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd63a9af3-a44a-4b71-bca5-f15570273573_800x457.png 848w, /__u/substackcdn.com/image/fetch/$s_!mLIF!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd63a9af3-a44a-4b71-bca5-f15570273573_800x457.png 1272w, /__u/substackcdn.com/image/fetch/$s_!mLIF!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd63a9af3-a44a-4b71-bca5-f15570273573_800x457.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>That is all you need to know to create the complete app, so I won&#8217;t go into great detail more here (the complete code is in my [GitHub](<a href="https://github.com/DataVizandAI/public_code/tree/main/dash-bootstrap">public_code/dash-bootstrap at main &#183; DataVizandAI/public_code &#183; GitHub</a>) repo and the README file will give you details of which file is which, so please visit that).</p><p>Below is the code that changes in the UI. You can see that we add two columns to the original row, and the second column contains code very similar to the first. In this column, a bar chart will be drawn, and the input is from a drop-down menu that contains a list of countries.</p><pre><code>dbc.Row([
            dbc.Col( # ...the original row content
            ),
            dbc.Col([
                html.Div('Total CO&#8322; Emissions', className='h3 text-danger'),
                html.Div("Choose a country to display the CO&#8322; emissions over time", className='text-secondary'),
                dcc.Dropdown(df.Entity.unique(), 'Canada', id='dropdown-selection'),
                dcc.Graph(id='graph-content'),
                ],
                className= DEFAULT_CLASS
            ),
        ]),</code></pre><p>To cater for this new chart, we need another callback function.</p><pre><code>@callback(
    Output('graph-content', 'figure'),
    Input('dropdown-selection', 'value')
)
def update_graph(value):
    dff = df[df.Entity==value]
    return px.bar(dff, x='Year', y='Annual CO&#8322; emissions', 
                  template='plotly_white')</code></pre><p>This simple function takes the value from the drop-down menu (the country) and plots a bar chart of emissions over time and returns the updated figure to the graph container with the ID &#8216;graph-content&#8217;.</p><h3>Conclusion</h3><p>In this tutorial, we built a Dash web application that visualizes CO&#8322; emissions using a choropleth map. We integrated Bootstrap components to enhance the layout.</p><p>Is this easier than Streamlit? You&#8217;ll probably think it is more in line with the way that Taipy or Mesop work, but which is the easiest method? This, at least to some extent, is down to personal preference.</p><p>I&#8217;ve used the open-source version of Dash here&#8202;&#8212;&#8202;there is an Enterprise version which provides you with tools to make developing and deploying sophisticated apps easier. I&#8217;ve no idea how much it costs.</p><p>This was, in the main, an exercise to help me make my mind up which data visualisation framework I prefer, and I have to report that I still don&#8217;t think I am any the wiser. Perhaps you are. I&#8217;d very much like to hear what you think.</p><div><hr></div><p>Thanks for reading, and I hope this was useful. If you would like to read more of my stuff, most of it is on <a href="https://medium.com/@alan-jones">Medium</a> and also on my <a href="https://datavizandai.github.io/">website</a> (if you aren&#8217;t a Medium member). I also intend to post more complete article here on Substack.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Hands on Data Visualization, Data Science, AI and Python! Subscribe for free to receive new posts.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p>Here are some useful links:</p><ul><li><p><a href="https://dash.plotly.com/">Dash (open source docs)</a></p></li><li><p><a href="https://dash-bootstrap-components.opensource.faculty.ai/">Dash Bootstrap Components</a></p></li><li><p><a href="https://ourworldindata.org/">Our World in Data</a></p></li><li><p>[The repo for this code](<a href="https://github.com/DataVizandAI/public_code/tree/main/dash-bootstrap">public_code/dash-bootstrap at main &#183; DataVizandAI/public_code &#183; GitHub</a>).</p></li></ul><div><hr></div><p><em>All images are by me, the author, unless otherwise indicated</em></p><p><em>I am not connected with any of the companies mentioned in this article except as a user of their products</em></p>]]></content:encoded></item><item><title><![CDATA[Jupyter Notebook Intelligence]]></title><description><![CDATA[Bringing the power of Copilot to Jupyter Labs - full article]]></description><link>https://technofile.substack.com/p/jupyter-notebook-intelligence</link><guid isPermaLink="false">https://technofile.substack.com/p/jupyter-notebook-intelligence</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Tue, 18 Feb 2025 16:55:29 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!68Sw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce9f3b61-c045-499c-a1dd-169ea4631f39_1200x719.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!68Sw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce9f3b61-c045-499c-a1dd-169ea4631f39_1200x719.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!68Sw!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce9f3b61-c045-499c-a1dd-169ea4631f39_1200x719.png 424w, /__u/substackcdn.com/image/fetch/$s_!68Sw!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce9f3b61-c045-499c-a1dd-169ea4631f39_1200x719.png 848w, /__u/substackcdn.com/image/fetch/$s_!68Sw!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce9f3b61-c045-499c-a1dd-169ea4631f39_1200x719.png 1272w, /__u/substackcdn.com/image/fetch/$s_!68Sw!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce9f3b61-c045-499c-a1dd-169ea4631f39_1200x719.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!68Sw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce9f3b61-c045-499c-a1dd-169ea4631f39_1200x719.png" width="1200" height="719" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ce9f3b61-c045-499c-a1dd-169ea4631f39_1200x719.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:719,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!68Sw!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce9f3b61-c045-499c-a1dd-169ea4631f39_1200x719.png 424w, /__u/substackcdn.com/image/fetch/$s_!68Sw!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce9f3b61-c045-499c-a1dd-169ea4631f39_1200x719.png 848w, /__u/substackcdn.com/image/fetch/$s_!68Sw!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce9f3b61-c045-499c-a1dd-169ea4631f39_1200x719.png 1272w, /__u/substackcdn.com/image/fetch/$s_!68Sw!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce9f3b61-c045-499c-a1dd-169ea4631f39_1200x719.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Appropriately, image generated with Microsoft Copilot in Edge</figcaption></figure></div><p>Is this the final feature that makes Jupyter Lab a complete IDE? Jupyter already has many features that make it a great IDE, but now it also has GitHub Copilot integration.</p><p>We&#8217;re going to explore Notebook Intelligence (NBI), a Jupyter Lab extension that brings the power of GitHub Copilot to Jupyter Lab. The author, Mehmet Bektas, has already written an introductory article, on Medium, which is well worth reading (<a href="https://blog.jupyter.org/introducing-notebook-intelligence-3648c306b91a">Introducing Notebook Intelligence!</a>). It shows you NBI&#8217;s main features and how to install the extension. Bektas also points out that, despite his close relationship with the Jupyter Project, NBI is not an official Jupyter extension. But I would like to point out that as a Jupyter Distinguished Contributor, this guy definitely knows his stuff.</p><p>Here I&#8217;m going to look at three ways we can get NBI to quickly create new code&#8202;&#8212;&#8202;both Notebooks and a Streamit program. I&#8217;ve published all of the code, including Notebooks that go step-by-step in an associated <a href="https://github.com/DataVizandAI/public_code/tree/main/jupyter-NBI">GitHub repo</a>.</p><p>We can use NBI to create a new Notebook in two ways&#8202;&#8212;&#8202;by giving prompts from within an existing Notebook or by using the <code>/newNotebook</code> command. We can also use NBI to create a new Python program using the <code>/newPythonFile</code> command, which we will use to create a Streamlit app.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/subscribe"><span>Subscribe now</span></a></p><h3>The NBI UI</h3><p>After installation, NBI can be seen in the toolbar on the left of the Jupyter Lab window. But before you can use it you need to log in to a GitHub account to use Copilot. This is straightforward, to log in NBI will provide you with a code you can copy and a link to click on. The link will take you to GitHub where you can enter the code and log in.</p><p>Now NBI is available. You may notice that code completions pop up as you type&#8202;&#8212;&#8202;just like Copilot in VSCode&#8202;&#8212;&#8202;just hit &lt;tab&gt; to accept them or carry on typing to ignore them.</p><p>You can also hit &lt;ctrl-G&gt; to bring up an NBI prompt in a Notebook. You can ask it to modify the code in that cell or create new code. A nice feature is that it shows you a <em>diff</em> of the original and the suggested code before you accept it. You can also edit the suggested code&#8202;&#8212;&#8202;the screenshot below illustrates this.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!gzlI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ee5280a-601c-412e-87d2-550710f1cc8d_800x435.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!gzlI!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ee5280a-601c-412e-87d2-550710f1cc8d_800x435.png 424w, /__u/substackcdn.com/image/fetch/$s_!gzlI!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ee5280a-601c-412e-87d2-550710f1cc8d_800x435.png 848w, /__u/substackcdn.com/image/fetch/$s_!gzlI!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ee5280a-601c-412e-87d2-550710f1cc8d_800x435.png 1272w, /__u/substackcdn.com/image/fetch/$s_!gzlI!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ee5280a-601c-412e-87d2-550710f1cc8d_800x435.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!gzlI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ee5280a-601c-412e-87d2-550710f1cc8d_800x435.png" width="800" height="435" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9ee5280a-601c-412e-87d2-550710f1cc8d_800x435.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:435,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!gzlI!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ee5280a-601c-412e-87d2-550710f1cc8d_800x435.png 424w, /__u/substackcdn.com/image/fetch/$s_!gzlI!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ee5280a-601c-412e-87d2-550710f1cc8d_800x435.png 848w, /__u/substackcdn.com/image/fetch/$s_!gzlI!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ee5280a-601c-412e-87d2-550710f1cc8d_800x435.png 1272w, /__u/substackcdn.com/image/fetch/$s_!gzlI!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ee5280a-601c-412e-87d2-550710f1cc8d_800x435.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>That is very similar to the way Copilot works in VSCode. And I used this feature to create a Notebook where I wrote almost no code myself. I simply wrote the prompts and accepted the suggestions. Below, you can see the result of a code suggestion from a blank cell. NBI creates the code and adds the prompt as a comment.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!NrUC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dcb1dc9-9c60-409e-9235-c0694a7811b9_800x156.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!NrUC!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dcb1dc9-9c60-409e-9235-c0694a7811b9_800x156.png 424w, /__u/substackcdn.com/image/fetch/$s_!NrUC!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dcb1dc9-9c60-409e-9235-c0694a7811b9_800x156.png 848w, /__u/substackcdn.com/image/fetch/$s_!NrUC!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dcb1dc9-9c60-409e-9235-c0694a7811b9_800x156.png 1272w, /__u/substackcdn.com/image/fetch/$s_!NrUC!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dcb1dc9-9c60-409e-9235-c0694a7811b9_800x156.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!NrUC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dcb1dc9-9c60-409e-9235-c0694a7811b9_800x156.png" width="800" height="156" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0dcb1dc9-9c60-409e-9235-c0694a7811b9_800x156.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:156,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!NrUC!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dcb1dc9-9c60-409e-9235-c0694a7811b9_800x156.png 424w, /__u/substackcdn.com/image/fetch/$s_!NrUC!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dcb1dc9-9c60-409e-9235-c0694a7811b9_800x156.png 848w, /__u/substackcdn.com/image/fetch/$s_!NrUC!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dcb1dc9-9c60-409e-9235-c0694a7811b9_800x156.png 1272w, /__u/substackcdn.com/image/fetch/$s_!NrUC!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0dcb1dc9-9c60-409e-9235-c0694a7811b9_800x156.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>(Note the circled icon in a Notebook cell where you can click instead of hitting &lt;ctrl-G&gt; to bring up the prompt.)</p><h3>The step-by-step approach to creating a new Notebook</h3><p>The Notebook that I created analyses climate change data since 1850. The raw data shows how temperatures have changed over that period and gives figures for each month, in each year. I wanted to see how the summer temperatures had changed over time so needed to reformat the data and average the summer months into a single figure. Then I wanted to draw a bar chart of the result.</p><p>Instead of writing the code to do this, I let NBI do all the work.</p><p>Well, most of it. I wrote a line to read in the raw data.</p><pre><code>import pandas as pd
df = pd.read_csv('HadCRUT-global-monthly.csv')</code></pre><p>This gave me a dataframe like this:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!IOhR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2ef1c52-b6ce-4c31-9b98-274d5efaa28c_767x235.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!IOhR!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2ef1c52-b6ce-4c31-9b98-274d5efaa28c_767x235.png 424w, /__u/substackcdn.com/image/fetch/$s_!IOhR!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2ef1c52-b6ce-4c31-9b98-274d5efaa28c_767x235.png 848w, /__u/substackcdn.com/image/fetch/$s_!IOhR!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2ef1c52-b6ce-4c31-9b98-274d5efaa28c_767x235.png 1272w, /__u/substackcdn.com/image/fetch/$s_!IOhR!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2ef1c52-b6ce-4c31-9b98-274d5efaa28c_767x235.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!IOhR!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2ef1c52-b6ce-4c31-9b98-274d5efaa28c_767x235.png" width="1200" height="367.6662320730117" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e2ef1c52-b6ce-4c31-9b98-274d5efaa28c_767x235.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:235,&quot;width&quot;:767,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!IOhR!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2ef1c52-b6ce-4c31-9b98-274d5efaa28c_767x235.png 424w, /__u/substackcdn.com/image/fetch/$s_!IOhR!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2ef1c52-b6ce-4c31-9b98-274d5efaa28c_767x235.png 848w, /__u/substackcdn.com/image/fetch/$s_!IOhR!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2ef1c52-b6ce-4c31-9b98-274d5efaa28c_767x235.png 1272w, /__u/substackcdn.com/image/fetch/$s_!IOhR!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2ef1c52-b6ce-4c31-9b98-274d5efaa28c_767x235.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You can see that the date combines the year and the month but I want to separate those and create a table of temperatures in monthly columns with a row for each year. So I opened a new cell and prompted NBI to create new columns for year and month. You can see the result below&#8202;&#8212;&#8202;the comment is the prompt that I gave.</p><pre><code># nbi-prompt: in df there is a column 'Time' that contains a date in 
# YYYY-MM format. Split this into two columns, one for YYYY and one for MM 
df['Year'] = df['Time'].str.split('-').str[0]
df['Month'] = df['Time'].str.split('-').str[1]
df.head()</code></pre><p>This gave me the extra columns I needed so the next thing was to reformat the table.</p><pre><code># nbi-prompt: create a new dataframe that uses the data from df. 
# The new dataframe should have columns for each of the months and rows for each year. 
#The cells should contain the Anomaly (deg C) values
new_df = df.pivot(index='Year', columns='Month', values='Anomaly (deg C)')
new_df.head()</code></pre><p>And then I wanted to create the &#8216;summer&#8217; column.</p><pre><code># nbi-prompt: Create a new column in new_df called summer that is the average of the months 06, 07 and 08
new_df['summer'] = new_df[['06', '07', '08']].mean(axis=1)
new_df.head()</code></pre><p>Remember, all of this code was written by NBI&#8202;&#8212;&#8202;I just wrote the prompts&#8202;&#8212;&#8202;and I ended up with the table that I wanted</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!eGg-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35297eff-f10f-4cfc-b008-f34ddcf426c9_800x180.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!eGg-!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35297eff-f10f-4cfc-b008-f34ddcf426c9_800x180.png 424w, /__u/substackcdn.com/image/fetch/$s_!eGg-!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35297eff-f10f-4cfc-b008-f34ddcf426c9_800x180.png 848w, /__u/substackcdn.com/image/fetch/$s_!eGg-!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35297eff-f10f-4cfc-b008-f34ddcf426c9_800x180.png 1272w, /__u/substackcdn.com/image/fetch/$s_!eGg-!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35297eff-f10f-4cfc-b008-f34ddcf426c9_800x180.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!eGg-!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35297eff-f10f-4cfc-b008-f34ddcf426c9_800x180.png" width="1200" height="270" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/35297eff-f10f-4cfc-b008-f34ddcf426c9_800x180.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:180,&quot;width&quot;:800,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!eGg-!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35297eff-f10f-4cfc-b008-f34ddcf426c9_800x180.png 424w, /__u/substackcdn.com/image/fetch/$s_!eGg-!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35297eff-f10f-4cfc-b008-f34ddcf426c9_800x180.png 848w, /__u/substackcdn.com/image/fetch/$s_!eGg-!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35297eff-f10f-4cfc-b008-f34ddcf426c9_800x180.png 1272w, /__u/substackcdn.com/image/fetch/$s_!eGg-!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35297eff-f10f-4cfc-b008-f34ddcf426c9_800x180.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Now I wanted a chart and that was easily created with the following prompt:</p><pre><code>Draw a matplotlib bar chart of 'summer' over 'Year'</code></pre><p>This gave me a suitable chart but all in one colour, so I selected the code in the cell hit &lt;Ctrl-G&gt; and asked it to make the positive bars red and the negative ones blue. NBI came up with a diff pane.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Kdb6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d9072ed-429a-45ea-b180-851cd23648cf_800x315.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Kdb6!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d9072ed-429a-45ea-b180-851cd23648cf_800x315.png 424w, /__u/substackcdn.com/image/fetch/$s_!Kdb6!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d9072ed-429a-45ea-b180-851cd23648cf_800x315.png 848w, /__u/substackcdn.com/image/fetch/$s_!Kdb6!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d9072ed-429a-45ea-b180-851cd23648cf_800x315.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Kdb6!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d9072ed-429a-45ea-b180-851cd23648cf_800x315.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Kdb6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d9072ed-429a-45ea-b180-851cd23648cf_800x315.png" width="800" height="315" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d9072ed-429a-45ea-b180-851cd23648cf_800x315.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:315,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Kdb6!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d9072ed-429a-45ea-b180-851cd23648cf_800x315.png 424w, /__u/substackcdn.com/image/fetch/$s_!Kdb6!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d9072ed-429a-45ea-b180-851cd23648cf_800x315.png 848w, /__u/substackcdn.com/image/fetch/$s_!Kdb6!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d9072ed-429a-45ea-b180-851cd23648cf_800x315.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Kdb6!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d9072ed-429a-45ea-b180-851cd23648cf_800x315.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You can see the original code was adequate and the new code added the colours that I wanted. But the x-axis is a bit of a mess so I went through the same procedure to ask it to rotate the labels by 45 deg. and to only mark every 10th year. The resulting chart was fine.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!qjEe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51f8584d-1a47-48f5-9db5-262e00f3c152_782x594.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!qjEe!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51f8584d-1a47-48f5-9db5-262e00f3c152_782x594.png 424w, /__u/substackcdn.com/image/fetch/$s_!qjEe!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51f8584d-1a47-48f5-9db5-262e00f3c152_782x594.png 848w, /__u/substackcdn.com/image/fetch/$s_!qjEe!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51f8584d-1a47-48f5-9db5-262e00f3c152_782x594.png 1272w, /__u/substackcdn.com/image/fetch/$s_!qjEe!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51f8584d-1a47-48f5-9db5-262e00f3c152_782x594.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!qjEe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51f8584d-1a47-48f5-9db5-262e00f3c152_782x594.png" width="782" height="594" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/51f8584d-1a47-48f5-9db5-262e00f3c152_782x594.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:594,&quot;width&quot;:782,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!qjEe!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51f8584d-1a47-48f5-9db5-262e00f3c152_782x594.png 424w, /__u/substackcdn.com/image/fetch/$s_!qjEe!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51f8584d-1a47-48f5-9db5-262e00f3c152_782x594.png 848w, /__u/substackcdn.com/image/fetch/$s_!qjEe!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51f8584d-1a47-48f5-9db5-262e00f3c152_782x594.png 1272w, /__u/substackcdn.com/image/fetch/$s_!qjEe!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51f8584d-1a47-48f5-9db5-262e00f3c152_782x594.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>That&#8217;s good but how about using Plotly? Again, I selected the codel and went through a series of prompts. The first asked NBI to convert to Plotly. That gave a standard chart but I then asked it to use the &#8216;plotly_white&#8217; template and the &#8216;inferno&#8217; colour scheme. The resulting code was this:</p><pre><code>colors = px.colors.sequential.Inferno
fig = px.bar(x=new_df.index, y=new_df['summer'], color=new_df['summer'], color_continuous_scale=colors)
fig.update_layout(xaxis_tickangle=45, xaxis_dtick=10)
fig.update_xaxes(title='Year')
fig.update_yaxes(title='Summer Anomaly (deg C)')
fig.update_layout(title='Summer Anomaly over Year')
fig.update_layout(template='plotly_white', width=800, height=600)</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!p2kh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7be598aa-ed99-477e-8081-f63c811b80b1_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!p2kh!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7be598aa-ed99-477e-8081-f63c811b80b1_800x600.png 424w, /__u/substackcdn.com/image/fetch/$s_!p2kh!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7be598aa-ed99-477e-8081-f63c811b80b1_800x600.png 848w, /__u/substackcdn.com/image/fetch/$s_!p2kh!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7be598aa-ed99-477e-8081-f63c811b80b1_800x600.png 1272w, /__u/substackcdn.com/image/fetch/$s_!p2kh!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7be598aa-ed99-477e-8081-f63c811b80b1_800x600.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!p2kh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7be598aa-ed99-477e-8081-f63c811b80b1_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7be598aa-ed99-477e-8081-f63c811b80b1_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!p2kh!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7be598aa-ed99-477e-8081-f63c811b80b1_800x600.png 424w, /__u/substackcdn.com/image/fetch/$s_!p2kh!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7be598aa-ed99-477e-8081-f63c811b80b1_800x600.png 848w, /__u/substackcdn.com/image/fetch/$s_!p2kh!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7be598aa-ed99-477e-8081-f63c811b80b1_800x600.png 1272w, /__u/substackcdn.com/image/fetch/$s_!p2kh!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7be598aa-ed99-477e-8081-f63c811b80b1_800x600.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>And that is pretty much the result that I wanted. I&#8217;ve skipped a few steps here but you can see the detailed version in the Notebook in the <a href="https://github.com/DataVizandAI/public_code/tree/main/jupyter-NBI">GitHub repo</a>.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/jupyter-notebook-intelligence?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/jupyter-notebook-intelligence?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><h3>Creating a complete Notebook</h3><p>As in VSCode NBI has a chat interface. You can use this as a way of generating code that you can insert into a Notebook and it is here that you can use the <code>/newNotebook</code> and <code>/newPythonFile</code> commands. These last two allow you to create entire Notebooks or Python programs.</p><p>To demonstrate this I concatenated prompts from the previous exercise to create a complete Notebook in one go.</p><p>The screenshot below shows the chat interface after I have prompted NBI to create a new Notebook.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!xxLO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34554c53-282c-4d51-a3ab-0a665631deb3_800x380.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!xxLO!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34554c53-282c-4d51-a3ab-0a665631deb3_800x380.png 424w, /__u/substackcdn.com/image/fetch/$s_!xxLO!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34554c53-282c-4d51-a3ab-0a665631deb3_800x380.png 848w, /__u/substackcdn.com/image/fetch/$s_!xxLO!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34554c53-282c-4d51-a3ab-0a665631deb3_800x380.png 1272w, /__u/substackcdn.com/image/fetch/$s_!xxLO!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34554c53-282c-4d51-a3ab-0a665631deb3_800x380.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!xxLO!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34554c53-282c-4d51-a3ab-0a665631deb3_800x380.png" width="1200" height="570" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/34554c53-282c-4d51-a3ab-0a665631deb3_800x380.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:380,&quot;width&quot;:800,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!xxLO!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34554c53-282c-4d51-a3ab-0a665631deb3_800x380.png 424w, /__u/substackcdn.com/image/fetch/$s_!xxLO!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34554c53-282c-4d51-a3ab-0a665631deb3_800x380.png 848w, /__u/substackcdn.com/image/fetch/$s_!xxLO!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34554c53-282c-4d51-a3ab-0a665631deb3_800x380.png 1272w, /__u/substackcdn.com/image/fetch/$s_!xxLO!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34554c53-282c-4d51-a3ab-0a665631deb3_800x380.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The input for the chat interface is at the bottom and the textual response above it. The code response is in the new Notebook you see on the right of the window. If you zoom in on the image you can see the complete prompt (otherwise look in the <a href="https://github.com/DataVizandAI/public_code/tree/main/jupyter-NBI">repo</a>) and the Notebook is a complete, nicely formatted and documented version of the previous code that produces the same Plotly chart.</p><h3>Creating a complete Streamlit app</h3><p>Creating a complete app was as simple as creating the last Notebook. Instead of <code>/newNotebook</code> the prompt is <code>newPythonFile</code> and I gave it the following prompt:</p><pre><code>Create a Python Streamlit app in the file weather.py that does the following:
Create a new pandas dataframe with the following data:'HadCRUT-global-monthly.csv'
The dataframe contains the following columns: 'Time', 'Anomaly (deg C)', 'Uncertainty (deg C)', 'Lower bound (deg C)', 'Upper bound (deg C)'.
The column 'Time' that contains a date in YYYY-MM format. Split this into two columns, one for years and one for months. Convert the numbers to names, e.g. 01 becomes January, 02 becomes February, etc.
Create a new dataframe that uses the data from the current one. 
The new dataframe should have columns for each of the months and rows for each year. 
The cells should contain the 'Anomaly (deg C)' values.
Create a new column in the new dataframe for the summer temperature that is the average of the months June, July and August).
Draw a Plotly Express bar chart of summer temperatures over each year.
Use the plotly_white template, change the size to 800 x 600 and use the 'inferno' color scheme.
Turn the x-axis labels 45 degrees and only show a label for every 10th year.
Add a suitable Streamlit title and subtitle for the page.</code></pre><p>NBI went on to produce a complete app in a Python file that is the equivalent of the Notebook.</p><h3>Conclusion</h3><p>This little experiment was done with v1.0.0; with this version, there was no &lt;Ctrl-G&gt; command when editing Python files. I suggested to Mehmet that this would be a good idea. Hey, Presto! There is now a v1.1.0 with that feature!</p><p>I&#8217;m seriously thinking that Jupyter Lab with NBI might replace my usual VSCode environment. I often find that I prototype stuff in a Notebook, first, and then move on to a Python program when I&#8217;m happy with the result. Jupyer Lab lets you do this as easily as VSCode and it supports Markdown, has a terminal and Git integration (via an extension)&#8202;&#8212;&#8202;what&#8217;s not to like?</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/jupyter-notebook-intelligence?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption">Thanks for reading &#8216;Hands on Data Visualization, Data Science, AI and Python&#8217;! This post is public so please share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/jupyter-notebook-intelligence?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/jupyter-notebook-intelligence?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p></div><p></p><h3>Notes</h3><p>The data used in this exercise was downloaded from <a href="https://www.metoffice.gov.uk/hadobs/hadcrut5/data/HadCRUT.5.0.2.0/download.html">Met Office Hadley Centre observations datasets</a> and is used under the <a href="https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/">UK Open Government Licence for Public Sector Information v3.0</a></p>]]></content:encoded></item><item><title><![CDATA[Instant RAG Applications with Pinecone Assistant]]></title><description><![CDATA[Pinecone Assistant is an online RAG/Vector database solution with a free tier]]></description><link>https://technofile.substack.com/p/instant-rag-applications-with-pinecone</link><guid isPermaLink="false">https://technofile.substack.com/p/instant-rag-applications-with-pinecone</guid><dc:creator><![CDATA[Alan Jones]]></dc:creator><pubDate>Wed, 12 Feb 2025 17:33:58 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3frx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Studying the US Constitution with RAG.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!3frx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!3frx!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png 424w, /__u/substackcdn.com/image/fetch/$s_!3frx!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png 848w, /__u/substackcdn.com/image/fetch/$s_!3frx!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png 1272w, /__u/substackcdn.com/image/fetch/$s_!3frx!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_webp, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!3frx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png" width="724" height="413.7142857142857" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:832,&quot;width&quot;:1456,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:2599662,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://technofile.substack.com/i/157007999?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!3frx!, /__u/technofile.substack.com/w_424, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png 424w, /__u/substackcdn.com/image/fetch/$s_!3frx!, /__u/technofile.substack.com/w_848, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png 848w, /__u/substackcdn.com/image/fetch/$s_!3frx!, /__u/technofile.substack.com/w_1272, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png 1272w, /__u/substackcdn.com/image/fetch/$s_!3frx!, /__u/technofile.substack.com/w_1456, /__u/technofile.substack.com/c_limit, /__u/technofile.substack.com/f_auto, /__u/technofile.substack.com/q_auto:good, /__u/technofile.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12cb7f72-2803-4cef-bf64-d3fd2c8f6c08_1792x1024.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><br>RAG apps don't need to be difficult to develop. Pinecone Assistant abstracts away all of the complexity and lets you interrogate your documents via a console or a Python API.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/subscribe"><span>Subscribe now</span></a></p><p><br>In the following article, I've explored a copy of the US Constitution and documentation from Wikipedia to simulate the sort of queries that a student or teacher might make. I also wrote a Streamlit application to answer questions about the Constitution, generate a study plan, and create multiple-choice questions (formatted as JSON).<br><br>The combination of Streamlit and Pinecone Assistant made writing the app remarkably easy. <br><br><strong>Read the article <a href="https://medium.com/p/7530858365bf">here (Medium members</a>) or <a href="https://datavizandai.github.io/2025/02/08/instant-RAG-with-Pinecone.html">here (my website)</a></strong></p><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://technofile.substack.com/p/instant-rag-applications-with-pinecone?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/technofile.substack.com/p/instant-rag-applications-with-pinecone?utm_source=substack&amp;utm_medium=email&amp;utm_content=share&amp;action=share"><span>Share</span></a></p><p><br><br></p>]]></content:encoded></item></channel></rss>