Python

Plotly figure_factory Module To Create Bullet Charts

In this article, we will discuss the method of creating bullet charts using the Plotly figure_factory module.

Syntax and Parameter List

The function syntax is shown below:

plotly.figure_factory.create_bullet(data, markers=None, measures=None, ranges=None,

subtitles=None, titles=None, orientation='h', range_colors=('rgb(200, 200, 200)', 'rgb(245,

245, 245)'
), measure_colors=('rgb(31, 119, 180)', 'rgb(176, 196, 221)'),

horizontal_spacing=None, vertical_spacing=None, scatter_options={}, **layout_options)

Required parameter list:

  1. Data – specifies the data used for the bullet plot
  2. Markers – specifies the values used for markers in each subplot
  3. Measures – specifies the quantitative measure of performance

Basic Bullet Plot

The following code illustrates how to use the Plotly figure_factory to create a bullet plot:

from plotly.figure_factory import create_bullet
data = [
  {"label": "revenue", "sublabel": "us$, in thousands",
   "range": [150, 225, 300], "performance": [220,270], "point": [250]},
  {"label": "Profit", "sublabel": "%", "range": [20, 25, 30],
   "performance": [21, 23], "point": [26]},
  {"label": "Order Size", "sublabel":"US$, average","range": [350, 500, 600],
   "performance": [100,320],"point": [550]},
  {"label": "New Customers", "sublabel": "count", "range": [1400, 2000, 2500],
   "performance": [1000, 1650],"point": [2100]},
  {"label": "Satisfaction", "sublabel": "out of 5","range": [3.5, 4.25, 5],
   "performance": [3.2, 4.7], "point": [4.4]}
]
fig = create_bullet(data, titles='label', subtitles='sublabel', markers='point', measures='performance', ranges='range')
fig.show()

Output figure:

You can set custom orientation by setting the orientation parameter as shown below:

fig = create_bullet(data, titles='label', subtitles='sublabel', markers='point', measures='performance', ranges='range', orientation='v')
fig.show()

This should create the following vertical plot:

Conclusion

This article discussed using the method of creating bullet charts using the Plotly figure_factory module with the parameters like data, markers, and measures. In addition, the function syntax and the basic bullet plot were covered.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list