'Using `matplotlib` to plot - <Figure size 432x288 with 0 Axes>

I've a huge data set with 158 columns and 3.1 million rows. I'm trying to plot univariate distibutions for that data set. Code is as given below.

dtf = pd.read_csv('hackathon_train_data1.csv')
dtf.head()
dtf.columns

Output was:

Index(['visit_id', 'cod_order_nbr', 'cod_orig_ord_nbr', 'src_bu_id', 'int_ref_nbr', 'cod_orig_bu_id', 'cod_src_bu_id', 'onln_flg', 'sohf_ord_dt', 'cod_init',
...
'csat_guid_v42', 'visit_num', 'chat_drawer_rightrail_open', 'chat_unavailable', 'chat_portal', 'ishmximpressions', 'pagination_c40', 'chat_intent_flag', 'coupon_code_stp_v96', 'isbreadcrumbhit_flg'], dtype='object', length=157)

Then I assigned the one of the column names to y and plotted the graph. Column cod_flg has only 2 entries, 0 and 1.

y = "cod_flg"  
ax = dtf[y].value_counts().sort_values().plot(kind="barh")  

Output was:
Graph
Then I tried to refine it as,

totals= []
for i in ax.patches:
    totals.append(i.get_width())
total = sum(totals)
for i in ax.patches:
     ax.text(i.get_width()+.3, i.get_y()+.20, 
     str(round((i.get_width()/total)*100, 2))+'%', 
     fontsize=10, color='black')
ax.grid(axis="x")
plt.suptitle(y, fontsize=20)
plt.show()  

It threw me this error:

Figure size 432x288 with 0 Axes

Do I need to modify this line? ax.text(i.get_width()+.3, i.get_y()+.20, str(round((i.get_width()/total)*100, 2))+'%', fontsize=10, color='black')



Solution 1:[1]

try without plt.show() , if you are using Google Colab

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aneesh R P Prakkulam