Skip to content Skip to sidebar Skip to footer

Issue In Error Bars In Seaborn Barplot - Python

(Have already looked at similar questions but they don't answer this query) I have a dataframe df1 with below structure {'token': {0: '180816_031', 1: '180816_031', 2: '180816_03

Solution 1:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns


d = {'token': {361: '180816_031', 119: '180816_031', 101: '180816_031', 135: '180816_031', 292: '180816_031',
               133: '180816_031', 99: '180816_031', 270: '180816_031', 19: '180816_031', 382: '180816_031',
               414: '180816_031', 267: '180816_031', 218: '180816_031', 398: '180816_031', 287: '180816_031',
               155: '180816_031', 392: '180816_031', 265: '180816_031', 239: '180816_031', 237: '180816_031'},
     'station': {361: 'deneb', 119: 'callisto', 101: 'callisto', 135: 'callisto', 292: 'callisto', 133: 'deneb',
                 99: 'callisto', 270: 'callisto', 19: 'deneb', 382: 'callisto', 414: 'deneb', 267: 'callisto',
                 218: 'deneb', 398: 'callisto', 287: 'deneb', 155: 'deneb', 392: 'deneb', 265: 'callisto',
                 239: 'callisto', 237: 'callisto'},
     'cycle_number': {361: 'cycle09', 119: 'cycle06', 101: 'cycle04', 135: 'cycle01', 292: 'cycle04', 133: 'cycle05',
                      99: 'cycle06', 270: 'cycle07', 19: 'cycle04', 382: 'cycle08', 414: 'cycle04', 267: 'cycle10',
                      218: 'cycle07', 398: 'cycle08', 287: 'cycle09', 155: 'cycle08', 392: 'cycle06', 265: 'cycle02',
                      239: 'cycle09', 237: 'cycle07'},
     'variable': {361: 'adj_high_quality_reads', 119: 'short_pass', 101: 'short_pass', 135: 'cell_mask_bilayers_sum',
                  292: 'adj_active_polymerase', 133: 'cell_mask_bilayers_sum', 99: 'short_pass',
                  270: 'adj_active_polymerase', 19: 'Unnamed: 0', 382: 'adj_high_quality_reads',
                  414: 'num_align_high_quality_reads', 267: 'adj_active_polymerase', 218: 'adj_single_pores',
                  398: 'num_align_high_quality_reads', 287: 'adj_active_polymerase', 155: 'cell_mask_bilayers_sum',
                  392: 'num_align_high_quality_reads', 265: 'adj_active_polymerase', 239: 'adj_single_pores',
                  237: 'adj_single_pores'},
     'value': {361: 99704.0, 119: 2072785.0, 101: 2061059.0, 135: 1682208.0, 292: 675306.0, 133: 1714292.0,
               99: 2072785.0, 270: 687988.0, 19: 19.0, 382: np.nan, 414: 285176.0, 267: 86914.0, 218: 948971.0,
               398: 405196.0, 287: 137926.0, 155: 1830032.0, 392: 480081.0, 265: 951689.0, 239: 681452.0,
               237: 882671.0}}
df = pd.DataFrame(d)


g = sns.barplot('token', 'value', data=df, hue='variable', capsize=0.1)

df5 = pd.DataFrame(df.groupby(['variable'])['value'].mean().reset_index())
i = 0
for p in g.patches:
    height = p.get_height()

    g.text(p.get_x() + p.get_width() / 2.,
           height + 3,
           "%.3f" % df5.at[i, 'value'],
           ha="center")
    i += 1
plt.show()

enter image description here


Post a Comment for "Issue In Error Bars In Seaborn Barplot - Python"