[{"data":1,"prerenderedAt":626},["ShallowReactive",2],{"content-query-JZOyOgqrwc":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"heading":10,"prompt":11,"tags":15,"files":18,"nav":6,"presets":19,"gallery":36,"body":38,"_type":619,"_id":620,"_source":621,"_file":622,"_stem":623,"_extension":624,"sitemap":625},"/tools/density-plot","tools",false,"","Density Plot Generator for Excel & CSV","Create density plots online from Excel and CSV data. Compare smooth distributions, overlap, and shape across groups with AI.","Density Plot Generator",{"prefix":12,"label":13,"placeholder":14},"Create a density plot","Describe the density plot you want to create","e.g. density plot of life expectancy by world region, filled curves, labeled peaks",[16,17],"charts","statistics",true,[20,26,31],{"label":21,"prompt":22,"dataset_url":23,"dataset_title":24,"dataset_citation":25},"Life expectancy by region","density plot of life expectancy distribution by world region; filled semi-transparent curves; one curve per region; label the peak of each curve; show the rightward shift from lower-income to higher-income regions","https://ourworldindata.org/grapher/life-expectancy.csv","Life expectancy","Our World in Data",{"label":27,"prompt":28,"dataset_url":29,"dataset_title":30,"dataset_citation":25},"GDP per capita by income group","density plot of log GDP per capita by World Bank income group (low, lower-middle, upper-middle, high income); log scale on x-axis; color each group; filled curves with transparency; add vertical median lines","https://ourworldindata.org/grapher/gdp-per-capita-worldbank.csv","GDP per capita (World Bank)",{"label":32,"prompt":33,"dataset_url":34,"dataset_title":35,"dataset_citation":25},"CO₂ emissions distribution","density plot of CO2 emissions per capita by continent for the most recent year; log scale on x-axis to handle skew; filled semi-transparent curves; label each curve at its peak; color by continent","https://ourworldindata.org/grapher/co-emissions-per-capita.csv","CO₂ emissions per capita",[37],"/img/tools/density-plot.png",{"type":39,"children":40,"toc":610},"root",[41,50,78,90,109,115,173,179,335,341,449,455,484,490,500,538,555,572],{"type":42,"tag":43,"props":44,"children":46},"element","h2",{"id":45},"what-is-a-density-plot",[47],{"type":48,"value":49},"text","What Is a Density Plot?",{"type":42,"tag":51,"props":52,"children":53},"p",{},[54,56,62,64,69,71,76],{"type":48,"value":55},"A ",{"type":42,"tag":57,"props":58,"children":59},"strong",{},[60],{"type":48,"value":61},"density plot",{"type":48,"value":63}," (formally a ",{"type":42,"tag":57,"props":65,"children":66},{},[67],{"type":48,"value":68},"kernel density estimate",{"type":48,"value":70}," or KDE plot) is a smooth, continuous curve that represents the ",{"type":42,"tag":57,"props":72,"children":73},{},[74],{"type":48,"value":75},"probability distribution of a numeric variable",{"type":48,"value":77},". Unlike a histogram, which groups data into discrete bins and is sensitive to bin width, a density plot uses a mathematical smoothing technique to produce a continuous curve where the area under the curve always equals 1. The height of the curve at any point estimates how likely it is to observe a value near that point — peaks correspond to the most common values, and the curve's spread reflects the variability in the data.",{"type":42,"tag":51,"props":79,"children":80},{},[81,83,88],{"type":48,"value":82},"The density plot's main strength is ",{"type":42,"tag":57,"props":84,"children":85},{},[86],{"type":48,"value":87},"comparing the shape of distributions across multiple groups simultaneously",{"type":48,"value":89},". Overlaid, semi-transparent KDE curves let you see at a glance whether groups peak at the same value, whether one group's distribution is wider or more skewed, and whether there are bimodal patterns (two peaks) that would be obscured in a single summary statistic. A classic example: plotting life expectancy for countries by world region shows a clear rightward shift from Sub-Saharan Africa to Europe, with each curve's width revealing how much within-region inequality exists. This comparison would require five separate histograms to achieve the same visual clarity.",{"type":42,"tag":51,"props":91,"children":92},{},[93,95,100,102,107],{"type":48,"value":94},"Density plots are widely used in statistics, data science, and research for ",{"type":42,"tag":57,"props":96,"children":97},{},[98],{"type":48,"value":99},"distributional comparisons",{"type":48,"value":101}," — checking whether a treatment group's outcome distribution shifted relative to control, visualizing how income distributions differ by country or decade, or confirming whether a variable is approximately normally distributed before applying parametric tests. They are particularly useful when you have ",{"type":42,"tag":57,"props":103,"children":104},{},[105],{"type":48,"value":106},"continuous data with 100+ observations per group",{"type":48,"value":108}," (for reliable KDE estimation) and want to show full distribution shape rather than just summary statistics.",{"type":42,"tag":43,"props":110,"children":112},{"id":111},"how-it-works",[113],{"type":48,"value":114},"How It Works",{"type":42,"tag":116,"props":117,"children":118},"ol",{},[119,130,146],{"type":42,"tag":120,"props":121,"children":122},"li",{},[123,128],{"type":42,"tag":57,"props":124,"children":125},{},[126],{"type":48,"value":127},"Upload your data",{"type":48,"value":129}," — provide a CSV or Excel file with at least one numeric column (the variable to plot) and optionally a categorical column for grouping. One row per observation; long format works best.",{"type":42,"tag":120,"props":131,"children":132},{},[133,138,140],{"type":42,"tag":57,"props":134,"children":135},{},[136],{"type":48,"value":137},"Describe the plot",{"type":48,"value":139}," — e.g. ",{"type":42,"tag":141,"props":142,"children":143},"em",{},[144],{"type":48,"value":145},"\"density plot of salary by department, filled curves, add median lines, log scale on x-axis\"",{"type":42,"tag":120,"props":147,"children":148},{},[149,154,156,163,165,171],{"type":42,"tag":57,"props":150,"children":151},{},[152],{"type":48,"value":153},"Get the visualization",{"type":48,"value":155}," — the AI writes Python code using ",{"type":42,"tag":157,"props":158,"children":160},"a",{"href":159},"https://plotly.com/python/",[161],{"type":48,"value":162},"Plotly",{"type":48,"value":164}," with ",{"type":42,"tag":157,"props":166,"children":168},{"href":167},"https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.gaussian_kde.html",[169],{"type":48,"value":170},"scipy",{"type":48,"value":172}," KDE to build smooth overlapping distribution curves",{"type":42,"tag":43,"props":174,"children":176},{"id":175},"interpreting-the-results",[177],{"type":48,"value":178},"Interpreting the Results",{"type":42,"tag":180,"props":181,"children":182},"table",{},[183,202],{"type":42,"tag":184,"props":185,"children":186},"thead",{},[187],{"type":42,"tag":188,"props":189,"children":190},"tr",{},[191,197],{"type":42,"tag":192,"props":193,"children":194},"th",{},[195],{"type":48,"value":196},"Visual element",{"type":42,"tag":192,"props":198,"children":199},{},[200],{"type":48,"value":201},"What it means",{"type":42,"tag":203,"props":204,"children":205},"tbody",{},[206,223,239,255,271,287,303,319],{"type":42,"tag":188,"props":207,"children":208},{},[209,218],{"type":42,"tag":210,"props":211,"children":212},"td",{},[213],{"type":42,"tag":57,"props":214,"children":215},{},[216],{"type":48,"value":217},"Peak of the curve",{"type":42,"tag":210,"props":219,"children":220},{},[221],{"type":48,"value":222},"Mode — the most common value in that group",{"type":42,"tag":188,"props":224,"children":225},{},[226,234],{"type":42,"tag":210,"props":227,"children":228},{},[229],{"type":42,"tag":57,"props":230,"children":231},{},[232],{"type":48,"value":233},"Width of the curve",{"type":42,"tag":210,"props":235,"children":236},{},[237],{"type":48,"value":238},"Spread — wide curve = high variance, narrow = concentrated values",{"type":42,"tag":188,"props":240,"children":241},{},[242,250],{"type":42,"tag":210,"props":243,"children":244},{},[245],{"type":42,"tag":57,"props":246,"children":247},{},[248],{"type":48,"value":249},"Position of the peak",{"type":42,"tag":210,"props":251,"children":252},{},[253],{"type":48,"value":254},"Central tendency — where most observations cluster",{"type":42,"tag":188,"props":256,"children":257},{},[258,266],{"type":42,"tag":210,"props":259,"children":260},{},[261],{"type":42,"tag":57,"props":262,"children":263},{},[264],{"type":48,"value":265},"Long tail to the right",{"type":42,"tag":210,"props":267,"children":268},{},[269],{"type":48,"value":270},"Right-skewed distribution — a few very large values",{"type":42,"tag":188,"props":272,"children":273},{},[274,282],{"type":42,"tag":210,"props":275,"children":276},{},[277],{"type":42,"tag":57,"props":278,"children":279},{},[280],{"type":48,"value":281},"Long tail to the left",{"type":42,"tag":210,"props":283,"children":284},{},[285],{"type":48,"value":286},"Left-skewed distribution — a few very small values",{"type":42,"tag":188,"props":288,"children":289},{},[290,298],{"type":42,"tag":210,"props":291,"children":292},{},[293],{"type":42,"tag":57,"props":294,"children":295},{},[296],{"type":48,"value":297},"Two peaks (bimodal)",{"type":42,"tag":210,"props":299,"children":300},{},[301],{"type":48,"value":302},"Two sub-populations with different typical values",{"type":42,"tag":188,"props":304,"children":305},{},[306,314],{"type":42,"tag":210,"props":307,"children":308},{},[309],{"type":42,"tag":57,"props":310,"children":311},{},[312],{"type":48,"value":313},"Curves shifting right across groups",{"type":42,"tag":210,"props":315,"children":316},{},[317],{"type":48,"value":318},"The variable increases systematically across those groups",{"type":42,"tag":188,"props":320,"children":321},{},[322,330],{"type":42,"tag":210,"props":323,"children":324},{},[325],{"type":42,"tag":57,"props":326,"children":327},{},[328],{"type":48,"value":329},"Overlap between curves",{"type":42,"tag":210,"props":331,"children":332},{},[333],{"type":48,"value":334},"Similarity between groups — heavy overlap = distributions are close",{"type":42,"tag":43,"props":336,"children":338},{"id":337},"example-prompts",[339],{"type":48,"value":340},"Example Prompts",{"type":42,"tag":180,"props":342,"children":343},{},[344,360],{"type":42,"tag":184,"props":345,"children":346},{},[347],{"type":42,"tag":188,"props":348,"children":349},{},[350,355],{"type":42,"tag":192,"props":351,"children":352},{},[353],{"type":48,"value":354},"Scenario",{"type":42,"tag":192,"props":356,"children":357},{},[358],{"type":48,"value":359},"What to type",{"type":42,"tag":203,"props":361,"children":362},{},[363,381,398,415,432],{"type":42,"tag":188,"props":364,"children":365},{},[366,371],{"type":42,"tag":210,"props":367,"children":368},{},[369],{"type":48,"value":370},"Regional comparison",{"type":42,"tag":210,"props":372,"children":373},{},[374],{"type":42,"tag":375,"props":376,"children":378},"code",{"className":377},[],[379],{"type":48,"value":380},"density plot of life expectancy by world region, filled curves, label peaks",{"type":42,"tag":188,"props":382,"children":383},{},[384,389],{"type":42,"tag":210,"props":385,"children":386},{},[387],{"type":48,"value":388},"Before/after treatment",{"type":42,"tag":210,"props":390,"children":391},{},[392],{"type":42,"tag":375,"props":393,"children":395},{"className":394},[],[396],{"type":48,"value":397},"density plot of test scores before and after intervention, overlay both curves",{"type":42,"tag":188,"props":399,"children":400},{},[401,406],{"type":42,"tag":210,"props":402,"children":403},{},[404],{"type":48,"value":405},"Income distribution",{"type":42,"tag":210,"props":407,"children":408},{},[409],{"type":42,"tag":375,"props":410,"children":412},{"className":411},[],[413],{"type":48,"value":414},"density plot of log income by decade from 1980 to 2020, show how distribution shifted",{"type":42,"tag":188,"props":416,"children":417},{},[418,423],{"type":42,"tag":210,"props":419,"children":420},{},[421],{"type":48,"value":422},"Quality control",{"type":42,"tag":210,"props":424,"children":425},{},[426],{"type":42,"tag":375,"props":427,"children":429},{"className":428},[],[430],{"type":48,"value":431},"density plot of product weight measurements by production line, add spec limit lines",{"type":42,"tag":188,"props":433,"children":434},{},[435,440],{"type":42,"tag":210,"props":436,"children":437},{},[438],{"type":48,"value":439},"Clinical trial",{"type":42,"tag":210,"props":441,"children":442},{},[443],{"type":42,"tag":375,"props":444,"children":446},{"className":445},[],[447],{"type":48,"value":448},"density plot of biomarker levels by treatment arm, add p-value annotation",{"type":42,"tag":43,"props":450,"children":452},{"id":451},"related-tools",[453],{"type":48,"value":454},"Related Tools",{"type":42,"tag":51,"props":456,"children":457},{},[458,460,466,468,474,476,482],{"type":48,"value":459},"Use the ",{"type":42,"tag":157,"props":461,"children":463},{"href":462},"/tools/ai-histogram-generator",[464],{"type":48,"value":465},"AI Histogram Generator",{"type":48,"value":467}," when you want to show the raw counts in discrete bins rather than a smoothed continuous curve — histograms are more honest about the actual data at small sample sizes (\u003C 100 observations per group). Use the ",{"type":42,"tag":157,"props":469,"children":471},{"href":470},"/tools/ridgeline-plot",[472],{"type":48,"value":473},"Ridgeline Plot Generator",{"type":48,"value":475}," when you have many groups (10+) to compare and want to stack the density curves vertically rather than overlay them. Use the ",{"type":42,"tag":157,"props":477,"children":479},{"href":478},"/tools/ai-violin-plot",[480],{"type":48,"value":481},"AI Violin Plot Generator",{"type":48,"value":483}," when you want to combine the density shape with summary statistics (median, IQR) in a single compact chart for a small number of groups.",{"type":42,"tag":43,"props":485,"children":487},{"id":486},"frequently-asked-questions",[488],{"type":48,"value":489},"Frequently Asked Questions",{"type":42,"tag":51,"props":491,"children":492},{},[493,498],{"type":42,"tag":57,"props":494,"children":495},{},[496],{"type":48,"value":497},"How does a density plot differ from a histogram?",{"type":48,"value":499},"\nA histogram divides the data into discrete bins and counts observations per bin — the result depends heavily on bin width and starting position. A density plot uses kernel density estimation to fit a smooth curve through the data, which makes it easier to see the distribution's shape, compare multiple groups by overlaying curves, and avoid the \"spiky\" appearance of histograms with many bins. The trade-off: a density plot can suggest smoothness that doesn't exist in small datasets. For fewer than ~50 observations, a histogram is more honest.",{"type":42,"tag":51,"props":501,"children":502},{},[503,508,510,515,517,522,524,529,531,536],{"type":42,"tag":57,"props":504,"children":505},{},[506],{"type":48,"value":507},"What bandwidth (smoothing) is used?",{"type":48,"value":509},"\nBy default, scipy uses ",{"type":42,"tag":57,"props":511,"children":512},{},[513],{"type":48,"value":514},"Silverman's rule",{"type":48,"value":516}," to automatically choose a bandwidth that balances smoothness against detail. If the result looks too smooth (hiding real features) or too jagged (over-fitting noise), ask for ",{"type":42,"tag":141,"props":518,"children":519},{},[520],{"type":48,"value":521},"\"increase the bandwidth\"",{"type":48,"value":523}," (smoother) or ",{"type":42,"tag":141,"props":525,"children":526},{},[527],{"type":48,"value":528},"\"decrease the bandwidth\"",{"type":48,"value":530}," (shows more detail). You can also specify a numeric value: ",{"type":42,"tag":141,"props":532,"children":533},{},[534],{"type":48,"value":535},"\"bandwidth 0.3\"",{"type":48,"value":537},".",{"type":42,"tag":51,"props":539,"children":540},{},[541,546,548,553],{"type":42,"tag":57,"props":542,"children":543},{},[544],{"type":48,"value":545},"My data is heavily right-skewed — should I use a log scale?",{"type":48,"value":547},"\nYes, for data like income, population, or revenue that span multiple orders of magnitude, ask for a ",{"type":42,"tag":141,"props":549,"children":550},{},[551],{"type":48,"value":552},"\"log scale on the x-axis\"",{"type":48,"value":554},". The AI will apply a log transform before computing the KDE, which produces a much more readable density curve that shows the shape of the bulk of the data without being dominated by extreme outliers.",{"type":42,"tag":51,"props":556,"children":557},{},[558,563,565,570],{"type":42,"tag":57,"props":559,"children":560},{},[561],{"type":48,"value":562},"Can I add a rug plot to show individual data points?",{"type":48,"value":564},"\nYes — ask for a ",{"type":42,"tag":141,"props":566,"children":567},{},[568],{"type":48,"value":569},"\"rug plot below the density curves\"",{"type":48,"value":571},". This adds a small tick mark at the x-axis for each observation, showing where the actual data points fall alongside the smooth KDE. It's especially useful for checking whether the KDE is a faithful representation of the raw data.",{"type":42,"tag":51,"props":573,"children":574},{},[575,580,581,586,588,608],{"type":42,"tag":57,"props":576,"children":577},{},[578],{"type":48,"value":579},"Can I show a 2D density plot (heatmap of two variables)?",{"type":48,"value":564},{"type":42,"tag":141,"props":582,"children":583},{},[584],{"type":48,"value":585},"\"2D density plot\"",{"type":48,"value":587}," or ",{"type":42,"tag":141,"props":589,"children":590},{},[591,593,599,601,606],{"type":48,"value":592},"\"density heatmap of ",{"type":42,"tag":594,"props":595,"children":596},"span",{},[597],{"type":48,"value":598},"variable A",{"type":48,"value":600}," vs ",{"type":42,"tag":594,"props":602,"children":603},{},[604],{"type":48,"value":605},"variable B",{"type":48,"value":607},"\"",{"type":48,"value":609},". The AI will use a 2D KDE to produce a contour or heatmap showing where observations cluster in the joint distribution of two numeric variables.",{"title":7,"searchDepth":611,"depth":611,"links":612},2,[613,614,615,616,617,618],{"id":45,"depth":611,"text":49},{"id":111,"depth":611,"text":114},{"id":175,"depth":611,"text":178},{"id":337,"depth":611,"text":340},{"id":451,"depth":611,"text":454},{"id":486,"depth":611,"text":489},"markdown","content:tools:024.density-plot.md","content","tools/024.density-plot.md","tools/024.density-plot","md",{"loc":4},1775502471196]