Skip to content

Box

Overview

The box trace type is used to display data as a box plot, which shows the distribution of data based on their quartiles, medians, and potential outliers. It's useful for statistical visualizations, as it highlights data spread and central tendency while accounting for variability.

You can control various aspects of the plot, such as the orientation, box and whisker styles, marker symbols, and points display. Additionally, you can show or hide outliers and configure hover labels for enhanced interaction.

Common Uses

  • Distribution Analysis: Understanding the distribution of quest-related data.
  • Outlier Detection: Identifying outliers in quest performance metrics.
  • Comparative Analysis: Comparing the performance of knights on different quests.

Check out the Attributes for the full set of configuration options

Examples

Common Configurations

Here's a simple box plot showing the distribution of sample data:

You can copy this code below to create this chart in your project:

models:
  - name: sample-data
    args:
      - echo
      - |
        category,value
        A,23
        A,15
        A,18
        A,30
        A,28
        B,40
        B,35
        B,31
        B,25
        B,29
traces:
  - name: Sample Box Plot
    model: ${ref(sample-data)}
    props:
      type: box
      x: ?{category}
      y: ?{value}
      boxpoints: "all"
      jitter: 1
      pointpos: -1.1
charts:
  - name: Sample Box Plot Chart
    traces:
      - ${ref(Sample Box Plot)}
    layout:
      title:
        text: Simple Box Plot<br><sub>Distribution of Values by Category</sub>
      xaxis:
        title:
          text: "Category"
      yaxis:
        title:
          text: "Value"

Here's a box plot showing the distribution of rewards earned by knights across different quests:

You can copy this code below to create this chart in your project:

models:
  - name: monty-python-quest-data-unique
    args:
      - curl
      - "https://raw.githubusercontent.com/visivo-io/data/refs/heads/main/monty_python_quests.csv"
traces:
  - name: Rewards Distribution by Quest
    model: ${ref(monty-python-quest-data-unique)}
    cohort_on: "person"
    props:
      type: box
      y: ?{person}
      x: ?{reward_gbp}
      boxpoints: "all"
      jitter: 1
      pointpos: -1.1
      orientation: h
charts:
  - name: Rewards Distribution Box Plot
    traces:
      - ${ref(Rewards Distribution by Quest)}
    layout:
      title:
        text: Horizontal Box Plot<br><sub>GBP Rewards Earned Across Quests</sub>
      xaxis:
        title:
          text: "Reward (GBP)"

In this example, we show how to display a box plot for the number of proclamations mades:

Here's the code:

models:
  - name: monty-python-quest-proclamations
    args:
      - curl
      - "https://raw.githubusercontent.com/visivo-io/data/refs/heads/main/monty_python_quests.csv"
traces:
  - name: Proclamations Box Plot
    model: ${ref(monty-python-quest-proclamations)}
    cohort_on: "person"
    props:
      type: box
      y: ?{proclamations_made}
      x: ?{enemy_encountered} 

charts:
  - name: Proclamations Box Plot with Outliers
    traces:
      - ${ref(Proclamations Box Plot)}
    layout:
      title:
        text: Cohorted Box Plot<br><sub>Proclamations Made Across Quests by Enemy</sub>
      xaxis:
        title:
          text: "Enemy"
      boxmode: group
      yaxis:
        title:
          text: "Proclamations Made"

A schema to validate plotly trace properties

Attributes

These attributes apply to traces where trace.props.type is set to box. You would configure these attributes on the trace with the trace.props object.

alignmentgroup: 'string' #(1)!
boxmean: 'any' #(2)!
boxpoints: 'any' #(3)!
customdata: 'array' #(4)!
customdatasrc: 'string' #(5)!
dx: 'number' #(6)!
dy: 'number' #(7)!
fillcolor: 'any' #(8)!
hoverinfo: 'array' #(9)!
hoverinfosrc: 'string' #(10)!
hoverlabel:
  align: 'array' #(11)!
  alignsrc: 'string' #(12)!
  bgcolor: 'color | array' #(13)!
  bgcolorsrc: 'string' #(14)!
  bordercolor: 'color | array' #(15)!
  bordercolorsrc: 'string' #(16)!
  font:
    color: color | array
    colorsrc: 'string' #(17)!
    family: 'string | array' #(18)!
    familysrc: 'string' #(19)!
    lineposition: 'array' #(20)!
    linepositionsrc: 'string' #(21)!
    shadow: 'string | array' #(22)!
    shadowsrc: 'string' #(23)!
    size: number | array
    sizesrc: 'string' #(24)!
    style: 'array' #(25)!
    stylesrc: 'string' #(26)!
    textcase: 'array' #(27)!
    textcasesrc: 'string' #(28)!
    variant: 'array' #(29)!
    variantsrc: 'string' #(30)!
    weight: 'integer | array' #(31)!
    weightsrc: 'string' #(32)!
  namelength: 'integer | array' #(33)!
  namelengthsrc: 'string' #(34)!
hoveron: 'string' #(35)!
hovertemplate: 'string | array' #(36)!
hovertemplatesrc: 'string' #(37)!
hovertext: 'string | array' #(38)!
hovertextsrc: 'string' #(39)!
ids: 'array' #(40)!
idssrc: 'string' #(41)!
jitter: 'number' #(42)!
legend: 'string' #(43)!
legendgroup: 'string' #(44)!
legendgrouptitle:
  font:
    color: any
    family: 'string' #(45)!
    lineposition: 'string' #(46)!
    shadow: 'string' #(47)!
    size: number
    style: 'any' #(48)!
    textcase: 'any' #(49)!
    variant: 'any' #(50)!
    weight: 'integer' #(51)!
  text: 'string' #(52)!
legendrank: 'number' #(53)!
legendwidth: 'number' #(54)!
line:
  color: 'any' #(55)!
  width: 'number' #(56)!
lowerfence: 'array' #(57)!
lowerfencesrc: 'string' #(58)!
marker:
  angle: 'number' #(59)!
  color: 'any' #(60)!
  line:
    color: 'any' #(61)!
    outliercolor: 'any' #(62)!
    outlierwidth: 'number' #(63)!
    width: 'number' #(64)!
  opacity: 'number' #(65)!
  outliercolor: 'any' #(66)!
  size: 'number' #(67)!
  symbol: 'any' #(68)!
mean: 'array' #(69)!
meansrc: 'string' #(70)!
median: 'array' #(71)!
mediansrc: 'string' #(72)!
metasrc: 'string' #(73)!
name: 'string' #(74)!
notched: 'boolean' #(75)!
notchspan: 'array' #(76)!
notchspansrc: 'string' #(77)!
notchwidth: 'number' #(78)!
offsetgroup: 'string' #(79)!
opacity: 'number' #(80)!
orientation: 'any' #(81)!
pointpos: 'number' #(82)!
q1: 'array' #(83)!
q1src: 'string' #(84)!
q3: 'array' #(85)!
q3src: 'string' #(86)!
quartilemethod: 'any' #(87)!
sd: 'array' #(88)!
sdmultiple: 'number' #(89)!
sdsrc: 'string' #(90)!
selected:
  marker:
    color: 'any' #(91)!
    opacity: 'number' #(92)!
    size: 'number' #(93)!
showlegend: 'boolean' #(94)!
showwhiskers: 'boolean' #(95)!
sizemode: 'any' #(96)!
stream:
  maxpoints: 'number' #(97)!
  token: 'string' #(98)!
text: 'string | array' #(99)!
textsrc: 'string' #(100)!
type: box
uid: 'string' #(101)!
unselected:
  marker:
    color: 'any' #(102)!
    opacity: 'number' #(103)!
    size: 'number' #(104)!
upperfence: 'array' #(105)!
upperfencesrc: 'string' #(106)!
visible: 'any' #(107)!
whiskerwidth: 'number' #(108)!
width: 'number' #(109)!
x: 'array' #(110)!
xaxis: 'string' #(111)!
xcalendar: 'any' #(112)!
xhoverformat: 'string' #(113)!
xperiodalignment: 'any' #(114)!
xsrc: 'string' #(115)!
y: 'array' #(116)!
yaxis: 'string' #(117)!
ycalendar: 'any' #(118)!
yhoverformat: 'string' #(119)!
yperiodalignment: 'any' #(120)!
ysrc: 'string' #(121)!
zorder: 'integer' #(122)!
  1. Set several traces linked to the same position axis or matching axes to the same alignmentgroup. This controls whether bars compute their positional range dependently or independently.
  2. If true, the mean of the box(es)' underlying distribution is drawn as a dashed line inside the box(es). If sd the standard deviation is also drawn. Defaults to true when mean is set. Defaults to sd when sd is set Otherwise defaults to false.
  3. If outliers, only the sample points lying outside the whiskers are shown If suspectedoutliers, the outlier points are shown and points either less than 4Q1-3Q3 or greater than 4Q3-3Q1 are highlighted (see outliercolor) If all, all sample points are shown If false, only the box(es) are shown with no sample points Defaults to suspectedoutliers when marker.outliercolor or marker.line.outliercolor is set. Defaults to all under the q1/median/q3 signature. Otherwise defaults to outliers.
  4. Assigns extra data each datum. This may be useful when listening to hover, click and selection events. Note that, scatter traces also appends customdata items in the markers DOM elements
  5. Sets the source reference on Chart Studio Cloud for customdata.
  6. Sets the x coordinate step for multi-box traces set using q1/median/q3.
  7. Sets the y coordinate step for multi-box traces set using q1/median/q3.
  8. Sets the fill color. Defaults to a half-transparent variant of the line color, marker color, or marker line color, whichever is available.
  9. Determines which trace information appear on hover. If none or skip are set, no information is displayed upon hovering. But, if none is set, click and hover events are still fired.
  10. Sets the source reference on Chart Studio Cloud for hoverinfo.
  11. Sets the horizontal alignment of the text content within hover label box. Has an effect only if the hover label text spans more two or more lines
  12. Sets the source reference on Chart Studio Cloud for align.
  13. Sets the background color of the hover labels for this trace
  14. Sets the source reference on Chart Studio Cloud for bgcolor.
  15. Sets the border color of the hover labels for this trace.
  16. Sets the source reference on Chart Studio Cloud for bordercolor.
  17. Sets the source reference on Chart Studio Cloud for color.
  18. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  19. Sets the source reference on Chart Studio Cloud for family.
  20. Sets the kind of decoration line(s) with text, such as an under, over or through as well as combinations e.g. under+over, etc.
  21. Sets the source reference on Chart Studio Cloud for lineposition.
  22. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  23. Sets the source reference on Chart Studio Cloud for shadow.
  24. Sets the source reference on Chart Studio Cloud for size.
  25. Sets whether a font should be styled with a normal or italic face from its family.
  26. Sets the source reference on Chart Studio Cloud for style.
  27. Sets capitalization of text. It can be used to make text appear in all-uppercase or all-lowercase, or with each word capitalized.
  28. Sets the source reference on Chart Studio Cloud for textcase.
  29. Sets the variant of the font.
  30. Sets the source reference on Chart Studio Cloud for variant.
  31. Sets the weight (or boldness) of the font.
  32. Sets the source reference on Chart Studio Cloud for weight.
  33. Sets the default length (in number of characters) of the trace name in the hover labels for all traces. -1 shows the whole name regardless of length. 0-3 shows the first 0-3 characters, and an integer >3 will show the whole name if it is less than that many characters, but if it is longer, will truncate to namelength - 3 characters and add an ellipsis.
  34. Sets the source reference on Chart Studio Cloud for namelength.
  35. Do the hover effects highlight individual boxes or sample points or both?
  36. Template string used for rendering the information that appear on hover box. Note that this will override hoverinfo. Variables are inserted using %{variable}, for example "y: %{y}" as well as %{xother}, {%xother}, {%_xother}, {%xother_}. When showing info for several points, xother will be added to those with different x positions from the first point. An underscore before or after (x|y)other will add a space on that side, only when this field is shown. Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example "Price: %{y:$.2f}". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. The variables available in hovertemplate are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data. Additionally, every attributes that can be specified per-point (the ones that are arrayOk: true) are available. Anything contained in tag <extra> is displayed in the secondary box, for example "{fullData.name}". To hide the secondary box completely, use an empty tag <extra></extra>.
  37. Sets the source reference on Chart Studio Cloud for hovertemplate.
  38. Same as text.
  39. Sets the source reference on Chart Studio Cloud for hovertext.
  40. Assigns id labels to each datum. These ids for object constancy of data points during animation. Should be an array of strings, not numbers or any other type.
  41. Sets the source reference on Chart Studio Cloud for ids.
  42. Sets the amount of jitter in the sample points drawn. If 0, the sample points align along the distribution axis. If 1, the sample points are drawn in a random jitter of width equal to the width of the box(es).
  43. Sets the reference to a legend to show this trace in. References to these legends are legend, legend2, legend3, etc. Settings for these legends are set in the layout, under layout.legend, layout.legend2, etc.
  44. Sets the legend group for this trace. Traces and shapes part of the same legend group hide/show at the same time when toggling legend items.
  45. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  46. Sets the kind of decoration line(s) with text, such as an under, over or through as well as combinations e.g. under+over, etc.
  47. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  48. Sets whether a font should be styled with a normal or italic face from its family.
  49. Sets capitalization of text. It can be used to make text appear in all-uppercase or all-lowercase, or with each word capitalized.
  50. Sets the variant of the font.
  51. Sets the weight (or boldness) of the font.
  52. Sets the title of the legend group.
  53. Sets the legend rank for this trace. Items and groups with smaller ranks are presented on top/left side while with reversed legend.traceorder they are on bottom/right side. The default legendrank is 1000, so that you can use ranks less than 1000 to place certain items before all unranked items, and ranks greater than 1000 to go after all unranked items. When having unranked or equal rank items shapes would be displayed after traces i.e. according to their order in data and layout.
  54. Sets the width (in px or fraction) of the legend for this trace.
  55. Sets the color of line bounding the box(es).
  56. Sets the width (in px) of line bounding the box(es).
  57. Sets the lower fence values. There should be as many items as the number of boxes desired. This attribute has effect only under the q1/median/q3 signature. If lowerfence is not provided but a sample (in y or x) is set, we compute the lower as the last sample point below 1.5 times the IQR.
  58. Sets the source reference on Chart Studio Cloud for lowerfence.
  59. Sets the marker angle in respect to angleref.
  60. Sets the marker color. It accepts either a specific color or an array of numbers that are mapped to the colorscale relative to the max and min values of the array or relative to marker.cmin and marker.cmax if set.
  61. Sets the marker.line color. It accepts either a specific color or an array of numbers that are mapped to the colorscale relative to the max and min values of the array or relative to marker.line.cmin and marker.line.cmax if set.
  62. Sets the border line color of the outlier sample points. Defaults to marker.color
  63. Sets the border line width (in px) of the outlier sample points.
  64. Sets the width (in px) of the lines bounding the marker points.
  65. Sets the marker opacity.
  66. Sets the color of the outlier sample points.
  67. Sets the marker size (in px).
  68. Sets the marker symbol type. Adding 100 is equivalent to appending -open to a symbol name. Adding 200 is equivalent to appending -dot to a symbol name. Adding 300 is equivalent to appending -open-dot or dot-open to a symbol name.
  69. Sets the mean values. There should be as many items as the number of boxes desired. This attribute has effect only under the q1/median/q3 signature. If mean is not provided but a sample (in y or x) is set, we compute the mean for each box using the sample values.
  70. Sets the source reference on Chart Studio Cloud for mean.
  71. Sets the median values. There should be as many items as the number of boxes desired.
  72. Sets the source reference on Chart Studio Cloud for median.
  73. Sets the source reference on Chart Studio Cloud for meta.
  74. Sets the trace name. The trace name appears as the legend item and on hover. For box traces, the name will also be used for the position coordinate, if x and x0 (y and y0 if horizontal) are missing and the position axis is categorical
  75. Determines whether or not notches are drawn. Notches displays a confidence interval around the median. We compute the confidence interval as median +/- 1.57 * IQR / sqrt(N), where IQR is the interquartile range and N is the sample size. If two boxes' notches do not overlap there is 95% confidence their medians differ. See https://sites.google.com/site/davidsstatistics/home/notched-box-plots for more info. Defaults to false unless notchwidth or notchspan is set.
  76. Sets the notch span from the boxes' median values. There should be as many items as the number of boxes desired. This attribute has effect only under the q1/median/q3 signature. If notchspan is not provided but a sample (in y or x) is set, we compute it as 1.57 * IQR / sqrt(N), where N is the sample size.
  77. Sets the source reference on Chart Studio Cloud for notchspan.
  78. Sets the width of the notches relative to the box' width. For example, with 0, the notches are as wide as the box(es).
  79. Set several traces linked to the same position axis or matching axes to the same offsetgroup where bars of the same position coordinate will line up.
  80. Sets the opacity of the trace.
  81. Sets the orientation of the box(es). If v (h), the distribution is visualized along the vertical (horizontal).
  82. Sets the position of the sample points in relation to the box(es). If 0, the sample points are places over the center of the box(es). Positive (negative) values correspond to positions to the right (left) for vertical boxes and above (below) for horizontal boxes
  83. Sets the Quartile 1 values. There should be as many items as the number of boxes desired.
  84. Sets the source reference on Chart Studio Cloud for q1.
  85. Sets the Quartile 3 values. There should be as many items as the number of boxes desired.
  86. Sets the source reference on Chart Studio Cloud for q3.
  87. Sets the method used to compute the sample's Q1 and Q3 quartiles. The linear method uses the 25th percentile for Q1 and 75th percentile for Q3 as computed using method #10 (listed on http://jse.amstat.org/v14n3/langford.html). The exclusive method uses the median to divide the ordered dataset into two halves if the sample is odd, it does not include the median in either half - Q1 is then the median of the lower half and Q3 the median of the upper half. The inclusive method also uses the median to divide the ordered dataset into two halves but if the sample is odd, it includes the median in both halves - Q1 is then the median of the lower half and Q3 the median of the upper half.
  88. Sets the standard deviation values. There should be as many items as the number of boxes desired. This attribute has effect only under the q1/median/q3 signature. If sd is not provided but a sample (in y or x) is set, we compute the standard deviation for each box using the sample values.
  89. Scales the box size when sizemode=sd Allowing boxes to be drawn across any stddev range For example 1-stddev, 3-stddev, 5-stddev
  90. Sets the source reference on Chart Studio Cloud for sd.
  91. Sets the marker color of selected points.
  92. Sets the marker opacity of selected points.
  93. Sets the marker size of selected points.
  94. Determines whether or not an item corresponding to this trace is shown in the legend.
  95. Determines whether or not whiskers are visible. Defaults to true for sizemode quartiles, false for sd.
  96. Sets the upper and lower bound for the boxes quartiles means box is drawn between Q1 and Q3 SD means the box is drawn between Mean +- Standard Deviation Argument sdmultiple (default 1) to scale the box size So it could be drawn 1-stddev, 3-stddev etc
  97. Sets the maximum number of points to keep on the plots from an incoming stream. If maxpoints is set to 50, only the newest 50 points will be displayed on the plot.
  98. The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
  99. Sets the text elements associated with each sample value. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (x,y) coordinates. To be seen, trace hoverinfo must contain a text flag.
  100. Sets the source reference on Chart Studio Cloud for text.
  101. Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
  102. Sets the marker color of unselected points, applied only when a selection exists.
  103. Sets the marker opacity of unselected points, applied only when a selection exists.
  104. Sets the marker size of unselected points, applied only when a selection exists.
  105. Sets the upper fence values. There should be as many items as the number of boxes desired. This attribute has effect only under the q1/median/q3 signature. If upperfence is not provided but a sample (in y or x) is set, we compute the upper as the last sample point above 1.5 times the IQR.
  106. Sets the source reference on Chart Studio Cloud for upperfence.
  107. Determines whether or not this trace is visible. If legendonly, the trace is not drawn, but can appear as a legend item (provided that the legend itself is visible).
  108. Sets the width of the whiskers relative to the box' width. For example, with 1, the whiskers are as wide as the box(es).
  109. Sets the width of the box in data coordinate If 0 (default value) the width is automatically selected based on the positions of other box traces in the same subplot.
  110. Sets the x sample data or coordinates. See overview for more info.
  111. Sets a reference between this trace's x coordinates and a 2D cartesian x axis. If x (the default value), the x coordinates refer to layout.xaxis. If x2, the x coordinates refer to layout.xaxis2, and so on.
  112. Sets the calendar system to use with x date data.
  113. Sets the hover text formatting rulefor x using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46By default the values are formatted using xaxis.hoverformat.
  114. Only relevant when the axis type is date. Sets the alignment of data points on the x axis.
  115. Sets the source reference on Chart Studio Cloud for x.
  116. Sets the y sample data or coordinates. See overview for more info.
  117. Sets a reference between this trace's y coordinates and a 2D cartesian y axis. If y (the default value), the y coordinates refer to layout.yaxis. If y2, the y coordinates refer to layout.yaxis2, and so on.
  118. Sets the calendar system to use with y date data.
  119. Sets the hover text formatting rulefor y using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46By default the values are formatted using yaxis.hoverformat.
  120. Only relevant when the axis type is date. Sets the alignment of data points on the y axis.
  121. Sets the source reference on Chart Studio Cloud for y.
  122. Sets the layer on which this trace is displayed, relative to other SVG traces on the same subplot. SVG traces with higher zorder appear in front of those with lower zorder.