Skip to content

Barpolar

Overview

The barpolar trace type is used to create bar charts in polar coordinates. This is particularly useful for displaying data that is cyclical or directional in nature, such as wind directions, time-of-day activities, or any phenomena that repeats over a circular dimension.

You have extensive control over the appearance of the bars through the marker and insidetextfont attributes. You can set colors, opacity, line styles, and more. The bars can be customized to start at a specific radial axis and extend to another, allowing for flexible representations.

Common Uses

  • Wind Rose Charts: Visualizing wind speed and direction distributions.
  • Circular Histograms: Displaying the frequency of events over a circular variable like time of day or compass direction.
  • Directional Data Representation: Showcasing data that has a directional component (e.g., animal migration patterns).
  • Cyclical Phenomena Visualization: Illustrating patterns that repeat over a cycle (e.g., seasonal sales data).

Check out the Attributes for the full set of configuration options

Examples

Common Configurations

Here's a simple barpolar chart showing activities over different compass directions:

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

models:
  - name: activity-data
    args:
      - echo
      - |
        direction,activity_level
        0,5
        45,10
        90,2
        135,8
        180,4
        225,6
        270,7
        315,3
traces:
  - name: Activity Level by Direction
    model: ${ref(activity-data)}
    props:
      type: barpolar
      r: ?{activity_level}
      theta: ?{direction}
      marker:
        color: "#1f77b4"
    order_by:
      - ?{direction}
charts:
  - name: Activity Level Polar Chart
    traces:
      - ${ref(Activity Level by Direction)}
    layout:
      polar:
        radialaxis:
          ticksuffix: "%"
          tickangle: 360
          tick0: 0
          dtick: 2
        angularaxis:
          rotation: 180
      margin: 
        l: 0 
        r: 0 
        b: 40
      title:
        text: Simple Barpolar Chart<br><sub>Activity Level by Direction</sub>

A wind rose chart is a common use of barpolar to display wind speed and direction frequencies:

Here's the updated code:

models:
  - name: wind-data
    args:
      - echo
      - |
        cardinal_order,direction,speed,count
        1,N,0-1 m/s,2
        1,N,1-2 m/s,3
        1,N,2-3 m/s,5
        2,NE,0-1 m/s,1
        2,NE,1-2 m/s,4
        2,NE,2-3 m/s,6
        3,E,0-1 m/s,2
        3,E,1-2 m/s,5
        3,E,2-3 m/s,3
        4,SE,0-1 m/s,3
        4,SE,1-2 m/s,2
        4,SE,2-3 m/s,4
        5,S,0-1 m/s,4
        5,S,1-2 m/s,5
        5,S,2-3 m/s,2
        6,SW,0-1 m/s,2
        6,SW,1-2 m/s,3
        6,SW,2-3 m/s,5
        7,W,0-1 m/s,1
        7,W,1-2 m/s,4
        7,W,2-3 m/s,6
        8,NW,0-1 m/s,2
        8,NW,1-2 m/s,5
        8,NW,2-3 m/s,3
traces:
  - name: Wind Rose
    model: ${ref(wind-data)}
    columns:
      bar_color: | 
        CASE speed 
          when '0-1 m/s' THEN '#1f77b4' 
          when '1-2 m/s' then '#ff7f0e' 
          when '2-3 m/s' then '#2ca02c' 
        end 
    props:
      type: barpolar
      r: ?{count}
      theta: ?{direction}
      text: ?{speed}
      marker:
        color: column(bar_color)
        opacity: .85
      hoverinfo: "theta+r+name"
    order_by: 
      - ?{cardinal_order}
charts:
  - name: Wind Rose Chart
    traces:
      - ${ref(Wind Rose)}
    layout:
      polar:
        radialaxis:
          ticksuffix: ""
          angle: 0
        angularaxis:
          direction: "clockwise"
          period: 8

      legend:
        title:
          text: "Wind Speed"
      title:
        text: Wind Rose Chart<br><sub>Wind Speed Distribution by Direction</sub>

You can customize the radial range to represent data starting and ending at specific radial positions:

Here's the code:

models:
  - name: custom-radial-data
    args:
      - echo
      - |
        direction,radial_start,radial_end
        0,1,3
        60,2,5
        120,3,6
        180,1,4
        240,2,7
        300,3,5
traces:
  - name: Custom Radial Barpolar
    model: ${ref(custom-radial-data)}
    props:
      type: barpolar
      theta: ?{direction}
      width: 30
      marker:
        color: "#d62728"
      opacity: 0.8
    order_by:
      - ?{direction}
charts:
  - name: Custom Radial Barpolar Chart
    traces:
      - ${ref(Custom Radial Barpolar)}
    layout:
      polar:
        radialaxis:
          visible: true
      title:
        text: Polar Bar with Custom Radial Range<br><sub>Bars Starting and Ending at Custom Radial Positions</sub>

A schema to validate plotly trace properties

Attributes

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

base: 'array' #(1)!
basesrc: 'string' #(2)!
customdata: array
customdatasrc: 'string' #(3)!
dr: number
dtheta: number
hoverinfo: array
hoverinfosrc: 'string' #(4)!
hoverlabel:
  align: array
  alignsrc: 'string' #(5)!
  bgcolor: array
  bgcolorsrc: 'string' #(6)!
  bordercolor: array
  bordercolorsrc: 'string' #(7)!
  font:
    color: array
    colorsrc: 'string' #(8)!
    family: 'string | array' #(9)!
    familysrc: 'string' #(10)!
    lineposition: array
    linepositionsrc: 'string' #(11)!
    shadow: 'string | array' #(12)!
    shadowsrc: 'string' #(13)!
    size: array
    sizesrc: 'string' #(14)!
    style: array
    stylesrc: 'string' #(15)!
    textcase: array
    textcasesrc: 'string' #(16)!
    variant: array
    variantsrc: 'string' #(17)!
    weight: array
    weightsrc: 'string' #(18)!
  namelength: array
  namelengthsrc: 'string' #(19)!
hovertemplate: 'string | array' #(20)!
hovertemplatesrc: 'string' #(21)!
hovertext: 'string | array' #(22)!
hovertextsrc: 'string' #(23)!
ids: array
idssrc: 'string' #(24)!
legend: string
legendgroup: 'string' #(25)!
legendgrouptitle:
  font:
    color: any
    family: 'string' #(26)!
    lineposition: any
    shadow: 'string' #(27)!
    size: number
    style: any
    textcase: any
    variant: any
    weight: integer
  text: 'string' #(28)!
legendrank: number
legendwidth: number
marker:
  autocolorscale: boolean
  cauto: boolean
  cmax: number
  cmid: number
  cmin: number
  color: array
  coloraxis: string
  colorbar:
    bgcolor: any
    bordercolor: any
    borderwidth: number
    exponentformat: any
    len: number
    lenmode: any
    minexponent: number
    nticks: integer
    orientation: any
    outlinecolor: any
    outlinewidth: number
    separatethousands: boolean
    showexponent: any
    showticklabels: boolean
    showtickprefix: any
    showticksuffix: any
    thickness: number
    thicknessmode: any
    tickangle: number
    tickcolor: any
    tickfont:
      color: any
      family: 'string' #(29)!
      lineposition: any
      shadow: 'string' #(30)!
      size: number
      style: any
      textcase: any
      variant: any
      weight: integer
    tickformat: 'string' #(31)!
    tickformatstops: array
    ticklabeloverflow: any
    ticklabelposition: any
    ticklabelstep: integer
    ticklen: number
    tickmode: any
    tickprefix: 'string' #(32)!
    ticks: any
    ticksuffix: 'string' #(33)!
    ticktext: array
    ticktextsrc: 'string' #(34)!
    tickvals: array
    tickvalssrc: 'string' #(35)!
    tickwidth: number
    title:
      font:
        color: any
        family: 'string' #(36)!
        lineposition: any
        shadow: 'string' #(37)!
        size: number
        style: any
        textcase: any
        variant: any
        weight: integer
      side: any
      text: 'string' #(38)!
    x: number
    xanchor: any
    xpad: number
    xref: any
    y: number
    yanchor: any
    ypad: number
    yref: any
  colorscale: any
  colorsrc: 'string' #(39)!
  line:
    autocolorscale: boolean
    cauto: boolean
    cmax: number
    cmid: number
    cmin: number
    color: array
    coloraxis: string
    colorscale: any
    colorsrc: 'string' #(40)!
    reversescale: boolean
    width: array
    widthsrc: 'string' #(41)!
  opacity: array
  opacitysrc: 'string' #(42)!
  pattern:
    bgcolor: array
    bgcolorsrc: 'string' #(43)!
    fgcolor: array
    fgcolorsrc: 'string' #(44)!
    fgopacity: number
    fillmode: any
    shape: array
    shapesrc: 'string' #(45)!
    size: array
    sizesrc: 'string' #(46)!
    solidity: array
    soliditysrc: 'string' #(47)!
  reversescale: boolean
  showscale: boolean
metasrc: 'string' #(48)!
name: 'string' #(49)!
offset: array
offsetsrc: 'string' #(50)!
opacity: number
r: array
rsrc: 'string' #(51)!
selected:
  marker:
    color: any
    opacity: number
  textfont:
    color: any
showlegend: boolean
stream:
  maxpoints: number
  token: 'string' #(52)!
subplot: string
text: 'string | array' #(53)!
textsrc: 'string' #(54)!
theta: array
thetasrc: 'string' #(55)!
thetaunit: any
type: barpolar
uid: 'string' #(56)!
unselected:
  marker:
    color: any
    opacity: number
  textfont:
    color: any
visible: any
width: array
widthsrc: 'string' #(57)!
  1. Sets where the bar base is drawn (in radial axis units). In stack barmode, traces that set base will be excluded and drawn in overlay mode instead.
  2. Sets the source reference on Chart Studio Cloud for base.
  3. Sets the source reference on Chart Studio Cloud for customdata.
  4. Sets the source reference on Chart Studio Cloud for hoverinfo.
  5. Sets the source reference on Chart Studio Cloud for align.
  6. Sets the source reference on Chart Studio Cloud for bgcolor.
  7. Sets the source reference on Chart Studio Cloud for bordercolor.
  8. Sets the source reference on Chart Studio Cloud for color.
  9. 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.
  10. Sets the source reference on Chart Studio Cloud for family.
  11. Sets the source reference on Chart Studio Cloud for lineposition.
  12. 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.
  13. Sets the source reference on Chart Studio Cloud for shadow.
  14. Sets the source reference on Chart Studio Cloud for size.
  15. Sets the source reference on Chart Studio Cloud for style.
  16. Sets the source reference on Chart Studio Cloud for textcase.
  17. Sets the source reference on Chart Studio Cloud for variant.
  18. Sets the source reference on Chart Studio Cloud for weight.
  19. Sets the source reference on Chart Studio Cloud for namelength.
  20. 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>.
  21. Sets the source reference on Chart Studio Cloud for hovertemplate.
  22. Same as text.
  23. Sets the source reference on Chart Studio Cloud for hovertext.
  24. Sets the source reference on Chart Studio Cloud for ids.
  25. 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.
  26. 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.
  27. 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.
  28. Sets the title of the legend group.
  29. 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.
  30. 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.
  31. Sets the tick label formatting rule 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.46
  32. Sets a tick label prefix.
  33. Sets a tick label suffix.
  34. Sets the source reference on Chart Studio Cloud for ticktext.
  35. Sets the source reference on Chart Studio Cloud for tickvals.
  36. 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.
  37. 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.
  38. Sets the title of the color bar.
  39. Sets the source reference on Chart Studio Cloud for color.
  40. Sets the source reference on Chart Studio Cloud for color.
  41. Sets the source reference on Chart Studio Cloud for width.
  42. Sets the source reference on Chart Studio Cloud for opacity.
  43. Sets the source reference on Chart Studio Cloud for bgcolor.
  44. Sets the source reference on Chart Studio Cloud for fgcolor.
  45. Sets the source reference on Chart Studio Cloud for shape.
  46. Sets the source reference on Chart Studio Cloud for size.
  47. Sets the source reference on Chart Studio Cloud for solidity.
  48. Sets the source reference on Chart Studio Cloud for meta.
  49. Sets the trace name. The trace name appears as the legend item and on hover.
  50. Sets the source reference on Chart Studio Cloud for offset.
  51. Sets the source reference on Chart Studio Cloud for r.
  52. The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
  53. Sets hover text elements associated with each bar. If a single string, the same string appears over all bars. If an array of string, the items are mapped in order to the this trace's coordinates.
  54. Sets the source reference on Chart Studio Cloud for text.
  55. Sets the source reference on Chart Studio Cloud for theta.
  56. Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
  57. Sets the source reference on Chart Studio Cloud for width.