Description

Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python.

Snippets

Standard import

   1 import numpy as np
   2 import pandas as pd
   3 import matplotlib.pyplot as plt

Bar graph with 3 y-axi

   1 x = np.arange(len(df['Index Column']))  # the label locations
   2 width = 0.20  # the width of the bars
   3 
   4 fig, ax1 = plt.subplots(figsize=(16,7))
   5 
   6 ax1.bar(x - 1 * width, df['Column A'], width, label='Column A', color='C0')
   7 ax1.set_ylabel('Column A', color='C0')
   8 ax1.yaxis.label.set_size(18)
   9 ax1.set_xticks(x)
  10 ax1.set_xticklabels(df['Index Column'], rotation='vertical', size=15)
  11 ax1.legend(bbox_to_anchor=(1, 1), prop={'size': 15})
  12 
  13 ax2 = ax1.twinx()          # instantiate a second axes that shares the same x-axis
  14 ax2.bar(x * width, df['Column B'], width, label='Column B', color='C1')
  15 ax2.set_ylabel('Column B', color='C1')
  16 ax2.yaxis.label.set_size(18)
  17 ax2.legend(bbox_to_anchor=(1, .9), prop={'size': 15})
  18 ax2.spines["right"].set_position(("axes", 1.0))
  19 
  20 ax3 = ax1.twinx()
  21 ax3.bar(x + 1 * width, df['Column C'], width, label='Column C', color='C2')
  22 #ax3.set_yscale('log')
  23 ax3.set_ylabel('Column C', color='C2')
  24 ax3.yaxis.label.set_size(18)
  25 ax3.legend(bbox_to_anchor=(1, .8), prop={'size': 15})
  26 ax3.spines["right"].set_position(("axes", 1.06))
  27 
  28 plt.show()

Howto/Python3/matplotlib (last edited 2020-04-08 17:09:18 by Burathar)