bar_chart


This function creates a bar chart.

bar_chart(**kwargs)

Input Variables

Name Description Type
plot_setup

Dictionary to configure the chart with the following keys:

  • name: Path + name of the figure
  • width: Figure width in SI units
  • height: Figure height in SI units
  • extension: File extension (e.g., 'png', 'svg')
  • dots_per_inch: Resolution in dots per inch
  • y_axis_label: Label for the y-axis
  • x_axis_label: Label for the x-axis
  • labels_size: Font size for labels
  • labels_color: Color of the labels
  • x_axis_size: Font size for x-axis labels
  • y_axis_size: Font size for y-axis labels
  • axises_color: Color of the axes
  • on_grid: Grid visibility (True/False)
  • y_log: Use logarithmic scale for y-axis (True/False)
  • x_log: Use logarithmic scale for x-axis (True/False)
  • colors: List of colors for the bars
  • opacity: Opacity level of the bars
Dictionary
dataset

Data to be plotted

List or array

Output Variables

Name Description Type
None

The function displays the plot on the screen and saves it in the same folder as the .ipynb or .py file.

None

Example 1

Use the bar_chart function to perform a task.

# Data
df = pd.DataFrame({'x': ['2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022'],
                   'action': [15.00, 16.00, 17.00, 18.00, 19.00, 20.00, 21.00, 22.00, 23.00, 24.00],
                   'comedy': [12.00, 13.00, 14.00, 15.00, 16.00, 17.00, 18.00, 19.00, 20.00, 21.00],
                   'drama': [9.00, 10.00, 11.00, 12.00, 13.00, 14.00, 15.00, 16.00, 17.00, 18.00],
                   'horror': [8.00, 9.00, 10.00, 11.00, 12.00, 13.00, 14.00, 15.00, 16.00, 17.00],
                   'romance': [10.00, 11.00, 12.00, 13.00, 14.00, 15.00, 16.00, 17.00, 18.00, 19.00]
                  })

# Chart setup  
chart_config = {
    'name': 'figure1-4-1',
    'width': 20,
    'height': 12,
    'bar width': .10,
    'opacity': 0.7,
    'y axis label': 'Revenue (USD billion)',
    'y axis size': 14,
    'x axis label': 'Year',
    'x axis size': 14,
    'axes color': 'green',
    'labels size': 14,
    'labels color': 'blue',
    'colors': ['#E53935', '#FFB300', '#1E88E5', '#4CAF50', '#9C27B0'],
    'on grid?': True,
    'y log': False,
    'dots per inch': 600,
    'extension': 'svg',
}

# Data statement 
data = {'dataset': df}

# Call function
bar_chart(dataset=data, plot_setup=chart_config)

Figure 1. Film Revenue by Category and Year.

Notebook example