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)!
- 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.
- Sets the source reference on Chart Studio Cloud for
base
. - Sets the source reference on Chart Studio Cloud for
customdata
. - Sets the source reference on Chart Studio Cloud for
hoverinfo
. - Sets the source reference on Chart Studio Cloud for
align
. - Sets the source reference on Chart Studio Cloud for
bgcolor
. - Sets the source reference on Chart Studio Cloud for
bordercolor
. - Sets the source reference on Chart Studio Cloud for
color
. - 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.
- Sets the source reference on Chart Studio Cloud for
family
. - Sets the source reference on Chart Studio Cloud for
lineposition
. - 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.
- Sets the source reference on Chart Studio Cloud for
shadow
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets the source reference on Chart Studio Cloud for
style
. - Sets the source reference on Chart Studio Cloud for
textcase
. - Sets the source reference on Chart Studio Cloud for
variant
. - Sets the source reference on Chart Studio Cloud for
weight
. - Sets the source reference on Chart Studio Cloud for
namelength
. - 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 inhovertemplate
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 arearrayOk: 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>
. - Sets the source reference on Chart Studio Cloud for
hovertemplate
. - Same as
text
. - Sets the source reference on Chart Studio Cloud for
hovertext
. - Sets the source reference on Chart Studio Cloud for
ids
. - 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.
- 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.
- 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.
- Sets the title of the legend group.
- 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.
- 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.
- 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
- Sets a tick label prefix.
- Sets a tick label suffix.
- Sets the source reference on Chart Studio Cloud for
ticktext
. - Sets the source reference on Chart Studio Cloud for
tickvals
. - 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.
- 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.
- Sets the title of the color bar.
- Sets the source reference on Chart Studio Cloud for
color
. - Sets the source reference on Chart Studio Cloud for
color
. - Sets the source reference on Chart Studio Cloud for
width
. - Sets the source reference on Chart Studio Cloud for
opacity
. - Sets the source reference on Chart Studio Cloud for
bgcolor
. - Sets the source reference on Chart Studio Cloud for
fgcolor
. - Sets the source reference on Chart Studio Cloud for
shape
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets the source reference on Chart Studio Cloud for
solidity
. - Sets the source reference on Chart Studio Cloud for
meta
. - Sets the trace name. The trace name appears as the legend item and on hover.
- Sets the source reference on Chart Studio Cloud for
offset
. - Sets the source reference on Chart Studio Cloud for
r
. - The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
- 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.
- Sets the source reference on Chart Studio Cloud for
text
. - Sets the source reference on Chart Studio Cloud for
theta
. - Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
- Sets the source reference on Chart Studio Cloud for
width
.