matplotlib

Bar plot in matplotlib

Create a bar plot in matplotlib based on your data. You can plot several series of bars in one figure. For each series, you can select color, width, alignment and transparency (alpha). Please provide label for bars to create legend. You can also produce bar plot with colors assigned to selected categorical column.

Please check Advanced options to change plot style, set title, axis labels and control legend position.

matplotlibbar

Required packages

You need below packages to use the code generated by recipe. All packages are automatically installed in MLJAR Studio.

matplotlib>=3.8.4

Interactive recipe

You can use below interactive recipe to generate code. This recipe is available in MLJAR Studio.

In the below recipe, we assume that you have following variables available in your notebook:

  • X (type DataFrame)

Python code

# Python code will be here

Code explanation

  1. Please select DataFrame.
  2. Please select columns for x and y axis. You can set color and transparency for each bar. There can be several bars in the one plot.
  3. You can customize each bars color, transparency(alpha), width and alignment.
  4. Please check Advanced options.
  5. You can set title and axis labels there.
  6. If you would like to control position of legend in your plot, you can do this in Advanced options. The default value is best, which means that matplotlib will search for position that do not overlay chart points.
  7. You can apply different style for bar figure.

Matplotlib cookbook

Code recipes from Matplotlib cookbook.

« Previous
Line plot