Scenario: You run a small store and want to analyze monthly sales using Pandas and visualize using Matplotlib.
import pandas as pd
import matplotlib.pyplot as plt
# Sales data
data = {
"Month": ["Jan", "Feb", "Mar", "Apr"],
"Sales": [300, 450, 500, 600]
}
# Load into DataFrame
sales_df = pd.DataFrame(data)
print(sales_df)
# Plot sales
plt.plot(sales_df["Month"], sales_df["Sales"], marker='o')
plt.title("Monthly Sales Trend")
plt.xlabel("Month")
plt.ylabel("Sales")
plt.grid(True)
plt.show()✅ This combines Pandas for data processing and Matplotlib for visualization
<div class="infographic-pysalestrend">
<style>
.infographic-pysalestrend {
--ink:#1a1a1a; --ink-soft:#5c5c5c; --paper:#fff; --paper-alt:#f0ece4;
--accent:#2563eb; --accent-soft:#e3ebfd; --line:#ddd6c9;
--mono-font:'IBM Plex Mono','SFMono-Regular',Menlo,monospace;
--display-font:'Fraunces',Georgia,serif; --body-font:'Inter',system-ui,sans-serif;
box-sizing:border-box; max-width:640px; margin:0 auto; font-family:var(--body-font); color:var(--ink); background:var(--paper);
}
.infographic-pysalestrend[data-theme="dark"] {
--ink:#e8e6e1; --ink-soft:#9a968c; --paper:#121212; --paper-alt:#1e1e26;
--accent:#5b8def; --accent-soft:#202942; --line:#2c313d;
}
.infographic-pysalestrend *,.infographic-pysalestrend *::before,.infographic-pysalestrend *::after{box-sizing:border-box;}
.infographic-pysalestrend .st-wrap{padding:0 clamp(1rem,4vw,2rem) 1.5rem;}
.infographic-pysalestrend h1{font-family:var(--display-font);font-weight:600;font-size:clamp(1.35rem,5vw,1.8rem);text-align:center;margin:1.5rem 0 0.25rem;letter-spacing:-0.01em;}
.infographic-pysalestrend .st-sub{text-align:center;color:var(--ink-soft);font-size:0.85rem;margin:0 0 1.2rem;}
.infographic-pysalestrend .code-line{text-align:center;font-family:var(--mono-font);font-size:0.76rem;color:var(--ink-soft);margin-bottom:1.1rem;line-height:1.6;}
.infographic-pysalestrend .code-line strong{color:var(--accent);}
.infographic-pysalestrend .edit-row{display:flex;justify-content:center;gap:0.5rem;margin-bottom:1rem;flex-wrap:wrap;}
.infographic-pysalestrend .edit-col{display:flex;flex-direction:column;align-items:center;gap:0.25rem;}
.infographic-pysalestrend .edit-col span{font-family:var(--mono-font);font-size:0.7rem;color:var(--ink-soft);font-weight:700;}
.infographic-pysalestrend .edit-col input{
font-family:var(--mono-font);font-size:0.82rem;font-weight:700;text-align:center;width:64px;
padding:0.35rem 0.3rem;border:1.5px solid var(--line);border-radius:5px;background:var(--paper-alt);color:var(--ink);
}
.infographic-pysalestrend .edit-col input:focus{outline:none;border-color:var(--accent);}
.infographic-pysalestrend .section-title{text-align:center;font-family:var(--mono-font);font-size:0.72rem;font-weight:700;text-transform:uppercase;letter-spacing:0.03em;color:var(--ink-soft);margin:1.1rem 0 0.5rem;}
.infographic-pysalestrend pre.st-pre{
font-family:var(--mono-font);font-size:0.8rem;line-height:1.6;background:var(--paper-alt);border:1px solid var(--line);
border-radius:8px;padding:0.7rem 0.85rem;margin:0 0 1rem;text-align:left;
}
.infographic-pysalestrend .chart-stage{display:flex;justify-content:center;background:var(--paper-alt);border:1px solid var(--line);border-radius:8px;padding:0.9rem;margin-bottom:0.6rem;}
.infographic-pysalestrend .chart-stage svg{width:100%;max-width:520px;height:auto;}
.infographic-pysalestrend .pt{transition:cx .3s,cy .3s;}
.infographic-pysalestrend .st-caption{text-align:center;font-size:0.85rem;color:var(--ink-soft);margin-top:0.6rem;}
@media (prefers-reduced-motion:reduce){.infographic-pysalestrend *,.infographic-pysalestrend *::before,.infographic-pysalestrend *::after{animation-duration:.001ms!important;transition-duration:.001ms!important;}}
</style>
<div class="st-wrap">
<h1>Monthly Sales Trend</h1>
<p class="st-sub">Edit the sales numbers — the DataFrame print and the chart both update live.</p>
<div class="code-line">
sales_df = pd.DataFrame(data) · print(sales_df)<br>
plt.plot(sales_df["Month"], sales_df["Sales"], marker=<strong>'o'</strong>) · plt.grid(True)
</div>
<div class="edit-row" id="editRow"></div>
<div class="section-title">print(sales_df)</div>
<pre class="st-pre" id="dfPre"></pre>
<div class="section-title">plt.show()</div>
<div class="chart-stage"><svg id="chartSvg" viewBox="0 0 460 260"></svg></div>
<p class="st-caption">Same DataFrame feeds both — pandas prints it as a table, matplotlib draws it as a line.</p>
</div>
<script>
(function(){
var root = document.currentScript.closest('.infographic-pysalestrend') || document.querySelector('.infographic-pysalestrend');
var bodyAttr = document.body.getAttribute('data-darkmode');
var dark = bodyAttr === 'true' ? true : bodyAttr === 'false' ? false : (document.cookie.match(/(?:^|;\s*)darkMode=([^;]+)/) || [])[1] === 'true';
if (dark) root.setAttribute('data-theme', 'dark');
var months = ['Jan', 'Feb', 'Mar', 'Apr'];
var sales = [300, 450, 500, 600];
var editRow = root.querySelector('#editRow');
var dfPre = root.querySelector('#dfPre');
var chartSvg = root.querySelector('#chartSvg');
months.forEach(function (m, i) {
var col = document.createElement('div');
col.className = 'edit-col';
col.innerHTML = '<span>' + m + '</span><input type="text" value="' + sales[i] + '" data-i="' + i + '" />';
editRow.appendChild(col);
});
editRow.querySelectorAll('input').forEach(function (inp) {
inp.addEventListener('input', function () {
var i = parseInt(inp.dataset.i, 10);
var v = parseFloat(inp.value);
sales[i] = isNaN(v) ? 0 : v;
render();
});
});
function renderDf() {
var lines = [' Month Sales'];
months.forEach(function (m, i) {
var idxStr = String(i);
var monthStr = m.padStart(5);
var salesStr = String(sales[i]).padStart(6);
lines.push(idxStr.padStart(2) + ' ' + monthStr + salesStr);
});
dfPre.textContent = lines.join('\n');
}
function svgNS(tag) { return document.createElementNS('http://www.w3.org/2000/svg', tag); }
function renderChart() {
chartSvg.innerHTML = '';
var W = 460, H = 260, PADL = 50, PADR = 20, PADT = 30, PADB = 40;
var maxV = Math.max.apply(null, sales) * 1.15;
var minV = 0;
function xAt(i) { return PADL + i * ((W - PADL - PADR) / (months.length - 1)); }
function yAt(v) { return H - PADB - ((v - minV) / (maxV - minV)) * (H - PADT - PADB); }
// gridlines + y labels
var steps = 5;
for (var s = 0; s <= steps; s++) {
var v = (maxV / steps) * s;
var gy = yAt(v);
var gl = svgNS('line');
gl.setAttribute('x1', PADL); gl.setAttribute('x2', W - PADR);
gl.setAttribute('y1', gy); gl.setAttribute('y2', gy);
gl.setAttribute('stroke', dark ? '#333' : '#e2ded4');
gl.setAttribute('stroke-width', '1');
chartSvg.appendChild(gl);
var lbl = svgNS('text');
lbl.setAttribute('x', PADL - 8); lbl.setAttribute('y', gy + 4);
lbl.setAttribute('text-anchor', 'end');
lbl.setAttribute('font-size', '10');
lbl.setAttribute('font-family', 'monospace');
lbl.setAttribute('fill', dark ? '#9a968c' : '#5c5c5c');
lbl.textContent = Math.round(v);
chartSvg.appendChild(lbl);
}
// title
var title = svgNS('text');
title.setAttribute('x', W / 2); title.setAttribute('y', 18);
title.setAttribute('text-anchor', 'middle');
title.setAttribute('font-size', '13');
title.setAttribute('font-weight', '700');
title.setAttribute('fill', dark ? '#e8e6e1' : '#1a1a1a');
title.textContent = 'Monthly Sales Trend';
chartSvg.appendChild(title);
// line
var pts = sales.map(function (v, i) { return xAt(i) + ',' + yAt(v); }).join(' ');
var poly = svgNS('polyline');
poly.setAttribute('points', pts);
poly.setAttribute('fill', 'none');
poly.setAttribute('stroke', dark ? '#5b8def' : '#2563eb');
poly.setAttribute('stroke-width', '2.5');
chartSvg.appendChild(poly);
sales.forEach(function (v, i) {
var c = svgNS('circle');
c.setAttribute('class', 'pt');
c.setAttribute('cx', xAt(i)); c.setAttribute('cy', yAt(v)); c.setAttribute('r', 5);
c.setAttribute('fill', dark ? '#5b8def' : '#2563eb');
chartSvg.appendChild(c);
var vlabel = svgNS('text');
vlabel.setAttribute('x', xAt(i)); vlabel.setAttribute('y', yAt(v) - 12);
vlabel.setAttribute('text-anchor', 'middle');
vlabel.setAttribute('font-size', '10');
vlabel.setAttribute('font-family', 'monospace');
vlabel.setAttribute('fill', dark ? '#e8e6e1' : '#1a1a1a');
vlabel.textContent = v;
chartSvg.appendChild(vlabel);
var xlabel = svgNS('text');
xlabel.setAttribute('x', xAt(i)); xlabel.setAttribute('y', H - PADB + 18);
xlabel.setAttribute('text-anchor', 'middle');
xlabel.setAttribute('font-size', '11');
xlabel.setAttribute('font-family', 'monospace');
xlabel.setAttribute('fill', dark ? '#9a968c' : '#5c5c5c');
xlabel.textContent = months[i];
chartSvg.appendChild(xlabel);
});
}
function render() { renderDf(); renderChart(); }
render();
})();
</script>
</div>