PlotSet LogoPlotSet

How to Create a Violin Plot

A step by step walkthrough for turning raw, row-level data into a published violin plot in PlotSet, including the bandwidth setting that decides whether the shape is real.

约 9 分钟

This guide covers how to create a violin plot in PlotSet, starting from a spreadsheet of individual observations and ending with a published chart you can embed or export. It is not five clicks: the one setting that actually matters, bandwidth, has no correct default, so you will nudge it and look at the result rather than accept whatever PlotSet picks first.

Nine minutes, roughly, if your data is already one row per observation with a group column and a value column. Pulling that from a report that only has group averages adds five more, because you'll need to go back to the source and get the underlying rows. A violin built from averages isn't a violin, it's a flat line pretending to be one.

你需要的数据

Two columns, one row per observation: a group label first, a numeric value second. Raw values, not pre-aggregated averages, one header row.

示例 CSV
WarehouseFulfillmentHours
Chicago4.2
Chicago4.8
Chicago3.9
Chicago9.1
Chicago4.5
Chicago4.1
Dallas6.0
Dallas6.3
Dallas5.8
Dallas6.1
Dallas12.4
Dallas6.5
Reno3.0
Reno3.2
Reno2.9
Reno3.4
Reno3.1
Reno7.8
备注

Every observation needs its own row. If your source file already has one row per group with an average fulfillment time, there is nothing left to draw a density from: go back and pull the order-level data instead.

Keep the group column as text. A warehouse code like "04" will still group correctly, but check the axis order once it is uploaded in case it got sorted numerically instead of the way you intended.

A blank cell in the value column is dropped from that group's density rather than treated as zero, which is the right behavior but can explain a row count that does not match your source file.

Uneven group sizes are fine. Chicago having forty rows and Reno having twelve does not break anything here, unlike some chart types that expect equal counts.

操作步骤

PlotSet 中从空白模板到完成图表的具体点击路径。

  1. 01

    Open the Violin Plot template

    From the PlotSet dashboard, start a new project and choose the Violin Plot template. It loads with sample data already in place, so you can see the two-column shape PlotSet expects before you touch your own file.

    PlotSet 的模板选择界面:左侧是图表分类列表,中间展开 Bar Charts 分类的模板网格,Bar Chart 模板卡片上显示「Select」按钮。
    每份指南都从这里开始:先选分类,再选模板,不管你要做哪种图表,用的都是同一个网格。
  2. 02

    Shape your sheet into observations, not summaries

    Put the group label in the first column and the raw numeric value in the second, one row per observation. If your export is a pivot table with an average per group, that is the wrong shape: pull the underlying rows from wherever the pivot came from.

  3. 03

    Import your data or connect a sheet

    Use the data panel to import a CSV or .xlsx file, paste rows directly from a spreadsheet, or connect a Google Sheet if the underlying numbers change regularly. PlotSet reads the first row as headers automatically.

    PlotSet 编辑器的数据视图:表格中 Name、Value、Region 三列填着加拿大各省的数据,旁边的「Data」面板提供 CSV 上传、「Magic Import」和 Google Sheet 同步。
    这里的数据视图取自一个条形图项目。你可以上传 CSV、用「Magic Import」从图片里提取数字,或同步 Google Sheet,每种图表类型的面板都一样。
  4. 04

    Map the group and value columns

    Confirm which column feeds the category axis and which feeds the density curve. This is usually right on the first try when your headers say what they mean, but double-check it if your sheet carries extra columns PlotSet had to guess between.

    PlotSet 数据面板中高亮的列绑定:「Label/time」对应 A 列,「Values」对应 B 列,「Filter/color」对应 C 列,下方是「Auto Binding」按钮。
    绑定决定哪一列作标签、哪一列提供数值、哪一列决定颜色。「Auto Binding」(自动绑定)会根据表头推测,所以要核对一遍,别想当然。
  5. 05

    Adjust the bandwidth and watch what changes

    Move the bandwidth slider up and down before settling on a value. Too high and two real peaks merge into one soft hump; too low and the curve gets bumpy from noise alone. Keep whichever shape survives a small nudge in both directions.

  6. 06

    Sort the groups by median

    Switch the group order from alphabetical to sorted by median value. Reno, Chicago, Dallas in that order tells the reader something; Chicago, Dallas, Reno alphabetically does not.

  7. 07

    Turn on the inner box and pick your colors

    Enable the inner box or median marker so a reader who wants the exact number does not have to eyeball the widest point of the curve. One color per group is standard; save a second, contrasting color for a group you specifically want to call out.

    PlotSet 编辑器停在「Preview」标签页:画布上是做好的 Violin Plot,右侧的设置面板用红框标出。
    Violin Plot 的「Preview」标签页。所有样式设置都在红框标出的这个面板里,每个设置各自占一个标签页:外观、标题、脚注,以及这种图表类型特有的选项。
  8. 08

    Wrap up: publish, embed or export

    Publish for a live, interactive chart with a tooltip on every group, grab the embed code to drop it into a page, or export a PNG, SVG or PDF if you need a static image for a deck.

从已加载示例数据的 Violin Plot 模板开始,再替换成你自己的数据。

打开模板

发布、嵌入或导出

最后一段路对每种图表都一样:「Share」(分享)把图表变成一个在线的公开链接和一段嵌入代码,「Export」(导出)把它输出成静态文件。

Share:公开链接与嵌入代码

打开嵌入代码和公开链接的开关,图表就发布出去了。链接可以放心发给任何人;嵌入代码以 iframe 的形式放进任意页面,悬停提示和交互效果都会保留。之后修改了图表,点「Recreate」就能把改动同步到链接和嵌入代码两边。

PlotSet 编辑器工具栏中高亮的「Share」按钮,紧挨着「Export」按钮。
点「Share」,完成的图表就会变成一个公开链接和一段嵌入代码。
PlotSet 的「Share」对话框:用于启用嵌入代码和公开链接的开关,「Link」「Embed」「Facebook」「Reddit」「Twitter」「LinkedIn」「Email」几个按钮,以及带「Copy」按钮的图表公开链接。
打开嵌入代码和公开链接的开关,然后复制链接或取用 iframe。之后再修改图表,点「Recreate」就能把改动同步给所有已拿到链接的人。

Export:SVG、PNG 或 JPG

「Export」会按你需要的尺寸输出一份静态副本。SVG 放到多大都清晰,还能在设计工具里继续编辑;幻灯片和文档用 PNG 或 JPG 最稳妥。想让图片在高分屏上够锐利,关键就是那个倍数设置。

PlotSet 编辑器工具栏中高亮的「Export」按钮。
要做成幻灯片或报告里的静态文件,就走「Export」这条路。
PlotSet 的「Export chart」对话框:倍数选择器设为 2x,宽高输入框填的是 1000 和 600,展开的格式菜单里列出 SVG、PNG 和 JPG。
SVG 放到多大都清晰,还能在设计工具里继续编辑;做幻灯片用 PNG 或 JPG 最稳妥。导出前先设好倍数,图片在高分屏上才够锐利。

Violin Plot 的样式提示

Trim the curve if your values are bounded

If your value column cannot go below zero, hours worked, order counts, percentages, turn on trimming so the density stops at the observed minimum instead of smoothing past it into negative territory that cannot exist.

Keep the inner summary on by default

A bare outline looks cleaner in a screenshot but leaves the reader guessing at the median. The inner box costs almost nothing visually and answers the first question anyone asks about a distribution: where is the middle.

One color family, not one color per group by default

Color coding every violin a different hue implies the groups are categorically different in some way beyond the axis label. A single color, or a light gradient across an ordered axis, keeps the reader's attention on shape rather than on a legend.

Widen the chart before you narrow the bandwidth

A violin squeezed into a narrow column looks noisier than the same data drawn wide, because horizontal detail gets compressed along with the shape. Give the chart more width first, then revisit the bandwidth: you may not need to smooth as hard as you thought.

制作 Violin Plot 时的常见错误

Every violin comes out as a thin, flat sliver

This is almost always pre-aggregated data: one row per group with an average, instead of one row per observation. Check your source file for the raw rows the average was calculated from and upload those instead.

Two groups that should look different look identical

The bandwidth is probably set too high for the amount of data you have, smoothing away the real differences between groups. Lower it step by step until the shapes diverge, then stop at the point where they stop changing.

The curve extends below zero on a value that cannot be negative

Kernel density smoothing does not know your values are bounded, so it draws density past the edge unless told otherwise. Turn on trimming to the observed range, or note in a caption that the tails past the boundary are a smoothing artifact.

深入了解 Violin Plot

不确定 Violin Plot 是否是正确选择?查看它是什么、何时使用以及何时不使用。

关于 Violin Plot

Violin Plot:常见问题

Aim for at least fifty observations per group before trusting the shape, and a few hundred before it is genuinely stable. PlotSet will still draw a violin from fewer rows, but the curve mostly reflects the bandwidth setting rather than the data at that size.

现在制作你的 Violin Plot

免费开始,300+ 模板任选。无需信用卡。