29.6 Charts with Matplotlib and seaborn in Python in Excel
Example first. Raja wants a horizontal bar chart of Amount by City, smallest at the bottom, and a histogram of delivery minutes. Both are a few lines of Python. The chart comes back as an image object in the cell; one right-click puts it over the grid where he can resize it next to his Excel table.
Python charts — in 30 seconds
What: Matplotlib (plt) and seaborn (sns) are imported for you. A plotting call in a Python cell returns the chart as an image object that you can preview, display over cells, or show inside the cell as an Excel value.
Why: Python charts give types Excel does not have built in (histograms with exact bins, pair plots, regression plots) and they are made from the same DataFrame, so they refresh with the data.
Tiny example: sns.histplot(df["Mins"], bins=[5, 10, 15, 20]) draws 3 bars: 2 orders took 5–9 minutes, 5 took 10–14, 3 took 15–20.
Python charts — 30 सेकंदात
काय: Matplotlib (plt) आणि seaborn (sns) तुमच्यासाठी import केलेले असतात. Python cell मधला plotting call chart image object म्हणून परत देतो, जो preview करता येतो, cells वर दाखवता येतो, किंवा Excel value म्हणून cell मध्ये दाखवता येतो.
का: Python charts मध्ये Excel मध्ये built in नसलेले प्रकार मिळतात (अचूक bins चे histograms, pair plots, regression plots) आणि ते त्याच DataFrame पासून बनतात, त्यामुळे data सोबत refresh होतात.
छोटं उदाहरण: sns.histplot(df["Mins"], bins=[5, 10, 15, 20]) 3 bars काढतो: 2 orders ना 5–9 मिनिटं लागली, 5 ना 10–14, 3 ना 15–20.
Python charts — 30 सेकंड में
क्या: Matplotlib (plt) और seaborn (sns) आपके लिए import किए हुए होते हैं. Python cell का plotting call chart को image object के रूप में लौटाता है, जिसे preview किया जा सकता है, cells के ऊपर दिखाया जा सकता है, या Excel value के रूप में cell के अंदर दिखाया जा सकता है.
क्यों: Python charts में वे प्रकार मिलते हैं जो Excel में built in नहीं हैं (सटीक bins वाले histograms, pair plots, regression plots) और वे उसी DataFrame से बनते हैं, इसलिए data के साथ refresh होते हैं.
छोटा उदाहरण: sns.histplot(df["Mins"], bins=[5, 10, 15, 20]) 3 bars बनाता है: 2 orders को 5–9 मिनट लगे, 5 को 10–14, 3 को 15–20.
First look at the data (before → after):
Expected result — Bars you should see (smallest to largest)
| Bar | Length (₹) |
|---|---|
| Sambhaji Nagar | 195 |
| Kolhapur | 232 |
| Nagpur | 240 |
| Nashik | 360 |
| Pune | 544 |
| Solapur | 1299 |
About this data: Teaching sample for a fictional shop “FreshGo Mart”. Figures and names (e.g. Rohan Patil) are made up for this lesson on charts with matplotlib and seaborn in python in.
Before table and formula as text
Before — Amount by City (data for the chart)
| City | Amount |
|---|---|
| Sambhaji Nagar | 195 |
| Kolhapur | 232 |
| Nagpur | 240 |
| Nashik | 360 |
| … | … |
About this data: Demo table only — not real customer or company data. Built to practise charts with matplotlib and seaborn in python in.
Formula / click path
city.plot(kind="barh") (pandas uses Matplotlib)
right-click › Display Plot over Cells (Ctrl+Alt+Shift+C)
Do it step by step:
- In a cell after df, type the bar chart code from the box below and commit with Ctrl+Enter. The cell shows an image card.
- Select the card icon to preview the chart.
- Right-click the cell and choose Display Plot over Cells (or press Ctrl+Alt+Shift+C). A copy floats over the grid; drag its corners to resize it.
- To show the picture inside the cell instead, switch the output to Excel Value; make the cell bigger to make the picture bigger.
- In another cell, type the histogram code and commit. Check the bar heights: 2, 5 and 3.
- Add axis labels and a title in the same cell with
plt.xlabel,plt.ylabelandplt.title.
स्टेप बाय स्टेप करून बघा:
- df नंतरच्या cell मध्ये खालच्या box मधला bar chart code type करा आणि Ctrl+Enter ने commit करा. Cell image card दाखवते.
- Chart preview करायला card icon निवडा.
- Cell वर right-click करून Display Plot over Cells निवडा (किंवा Ctrl+Alt+Shift+C दाबा). एक copy grid वर तरंगते; कोपरे ओढून size बदला.
- त्याऐवजी picture cell च्या आत दाखवायचं असेल तर output Excel Value करा; picture मोठं करायला cell मोठी करा.
- दुसऱ्या cell मध्ये histogram code type करून commit करा. Bars ची उंची तपासा: 2, 5 आणि 3.
- त्याच cell मध्ये
plt.xlabel,plt.ylabelआणिplt.titleने axis labels आणि title जोडा.
स्टेप बाय स्टेप करके देखें:
- df के बाद वाली cell में नीचे के box का bar chart code type करें और Ctrl+Enter से commit करें. Cell image card दिखाती है.
- Chart preview करने के लिए card icon चुनें.
- Cell पर right-click करके Display Plot over Cells चुनें (या Ctrl+Alt+Shift+C दबाएँ). एक copy grid के ऊपर तैरती है; कोने खींचकर size बदलें.
- इसके बजाय picture को cell के अंदर दिखाना हो तो output Excel Value करें; picture बड़ी करने के लिए cell बड़ी करें.
- दूसरी cell में histogram code type करके commit करें. Bars की ऊँचाई जाँचें: 2, 5 और 3.
- उसी cell में
plt.xlabel,plt.ylabelऔरplt.titleसे axis labels और title जोड़ें.
1. Horizontal bar chart with pandas + Matplotlib
city = df.groupby("City")["Amount"].sum().sort_values()
city.plot(kind="barh")
plt.xlabel("Amount (Rs)")
plt.title("Amount by City (fictional data)")
sort_values() puts the smallest total first, and a horizontal bar chart draws the first item at the bottom, so Solapur (₹1,299) ends up as the longest bar at the top. Bar lengths: Sambhaji Nagar 195, Kolhapur 232, Nagpur 240, Nashik 360, Pune 544, Solapur 1299.
2. seaborn bar chart straight from the DataFrame
sns.barplot(data=df, x="City", y="Amount", estimator="sum", errorbar=None)
plt.xticks(rotation=30)
plt.title("Amount by City")
estimator="sum" makes each bar the total Amount of the city (seaborn's default would be the average), and errorbar=None removes the black error lines that seaborn adds by default. Bars appear in the order the cities first appear in the data: Pune, Nashik, Nagpur, Kolhapur, Solapur, Sambhaji Nagar.
3. Histogram of delivery minutes with exact bins
sns.histplot(df["Mins"], bins=[5, 10, 15, 20])
plt.title("Delivery minutes")
| Bin (minutes) | Orders | Which orders |
|---|---|---|
| 5 to under 10 | 2 | BLK-1001, BLK-1006 |
| 10 to under 15 | 5 | BLK-1002, AMN-1003, BLK-1004, AMN-1008, BLK-1009 |
| 15 to 20 | 3 | AMN-1005, BLK-1007, BLK-1010 |
About this data: Made-up rows so you can copy the pattern for charts with matplotlib and seaborn in python in. Currencies may use ₹, £, € or $.
Expected output computed by running this exact code locally with pandas on the same fictional data (Python in Excel runs it in the Microsoft Cloud; numbers are the same, the look of the card may differ). The last bin includes its right edge (20); the others do not, which is how NumPy and seaborn define bins. Excel's own histogram chart and the FREQUENCY function use different edge rules, so always say which bins you used.
Getting the chart onto the sheet
| Option | How | Best for |
|---|---|---|
| Preview only | Select the card icon in the cell | Quick look while you work |
| Display Plot over Cells | Right-click › Display Plot over Cells, or Ctrl+Alt+Shift+C | A chart you resize and place next to tables (the original stays in the cell) |
| Picture in the cell | Python output menu › Excel Value (or Ctrl+Alt+Shift+M) | A small chart per row or a compact dashboard; size follows the cell |
About this data: Fictional worksheet used in class. Safe to edit; nothing here is live production data.
Python chart or Excel chart? If the chart must be formatted by colleagues who do not know Python, or must react to slicers, make an Excel chart from the spilled Excel values. Choose a Python chart when you need something Excel cannot draw easily (exact-bin histograms, box plots, pair plots, regression lines) or when the chart is part of an analysis already written in Python.
Indian-language labels. Microsoft's plotting page lists excel.FontPath.HINDI (Mangal font) for chart labels in Devanagari; without it non-Latin characters show as empty boxes. In this course we keep chart labels in English.
Microsoft sources (checked 7 October 2026): Create plots and charts with Python in Excel; Open-source libraries and Python in Excel; Python in Excel keyboard shortcuts.
Practice task (try it before you open the answer):
- Draw a bar chart of the number of orders per Platform.
- Say the bar heights.
- Display it over cells.
Answer
df["Platform"].value_counts().plot(kind="bar")thenplt.title("Orders by platform").- FreshGo 7, MarketRush 3 (value_counts sorts largest first).
- Right-click the cell › Display Plot over Cells, or press Ctrl+Alt+Shift+C.
Ravindra Bagale's Tip
Put the numbers next to every Python chart, as a small Excel-value table. A picture cannot be checked; the table behind it can.
Ravindra Bagale's Tip – मराठी
प्रत्येक Python chart शेजारी आकडे Excel-value table म्हणून ठेवा. Picture तपासता येत नाही; त्यामागची table तपासता येते.
Ravindra Bagale's Tip – हिंदी
हर Python chart के बगल में आँकड़े छोटी Excel-value table के रूप में रखें. Picture जाँची नहीं जा सकती; उसके पीछे की table जाँची जा सकती है.
Worked example — charts with matplotlib and seaborn in python in
Why
Sana Sheikh in Pune and Liam Murphy abroad both need a clear, repeatable way to use charts with matplotlib and seaborn in python in on a CityBasket Retail sheet without breaking totals.
What
Charts With Matplotlib And Seaborn In Python In is the Excel idea this page teaches. We will walk one tiny example end to end.
How
- Open a blank sheet. In A1 type a short label for charts with matplotlib and seaborn in python in.
- Enter a small made-up value for Sana Sheikh using € where money appears.
- Add a second value for Liam Murphy using ₹ so you see mixed currencies stay numeric.
- Apply the method from this lesson step by step (menu or formula as shown above).
- Check the result still works inside SUM or a simple check cell.
Formula / action
Follow the formula or ribbon steps shown in this lesson (keep values numeric).
Meaning: Once charts with matplotlib and seaborn in python in is correct on one row, copy the same pattern down the column.
Practice tasks (10+)
Try these on a blank sheet. Open a hint only if you are stuck. No quiz — just practice.
1. Rebuild the smallest example of charts with matplotlib and seaborn in python in on a blank sheet for BrightLedger Finance.
Hint: Use only the steps on this page. Keep numbers numeric.
2. Change one input for Priya Deshmukh and confirm the result updates.
Hint: If the result is stuck, check absolute vs relative references.
3. Repeat the same steps with a £ or € value for Liam Murphy.
Hint: Formatting must not break SUM.
4. Write the result meaning in one plain sentence next to the cell.
Hint: Imagine explaining it to a new joiners.
5. Add a second row and fill the method down.
Hint: Double-click the fill handle if the pattern is consistent.
6. Break the example on purpose, then fix it using this lesson.
Hint: Common break: text instead of a number.
7. Apply charts with matplotlib and seaborn in python in to a 5-row made-up BrightLedger Finance table.
Hint: Keep column headers clear.
8. Check your answer with a simple total or COUNT.
Hint: A wrong total usually means a format or key mismatch.
9. Swap ₹ and $ on one column and re-check totals.
Hint: Stored values stay the same; only the display changes.
10. List two mistakes beginners make with charts with matplotlib and seaborn in python in.
Hint: Look back at the tip box on this page.
11. Teach the steps out loud in under one minute.
Hint: Why → What → How.
12. Save the sheet as BrightLedger_practice.xlsx.
Hint: Use a clear file name for class.
Loading practice tasks...
- len(df) (Easy): How many rows are in the Order ID column?
- df['Amount'].sum() (Easy): Add up the Amount column.
- df['Qty'].max() (Easy): What is the largest value in the Qty column?
- df['Amount'].mean() (Easy): Find the average Amount, rounded to 0 decimals.
- value_counts() for App (Medium): How many rows have Channel "App"?
- groupby('Channel').sum() for Store (Medium): Add up Amount where Channel is "Store".
- df['Amount'].median() (Medium): Find the median of the Amount column.
- df['Amount'].min() (Medium): What is the smallest value in the Amount column?
- df[df['Qty']>=5] (Medium): How many rows have Qty of 5 or more?
- std() of Amount (Hard): Find the sample standard deviation of Amount, rounded to 1 decimal.
- groupby mean for Website (Hard): Find the average Amount where Channel is "Website", rounded to 0 decimals.
- idxmax() of Amount (Hard): Which Customer has the largest Amount?