123456789101112131415161718192021222324252627282930313233343536373839404142 |
- def bardot(df="dataframe", dim=(6, 4), bw=0.4, colorbar="#f2aa4cff", colordot=["#101820ff"], hbsize=4, r=300, ar=0,
- dotsize=6, valphabar=1, valphadot=1, markerdot="o", errorbar=True, show=False, ylm=None, axtickfontsize=9,
- axtickfontname="Arial", axlabelfontsize=9, axlabelfontname="Arial", yerrlw=None, yerrcw=None, axxlabel=None,
- axylabel=None, figtype='png'):
- # set axis labels to None
- _x = None
- _y = None
- xbar = np.arange(len(df.columns.to_numpy()))
- color_list_bar = colorbar
- color_list_dot = colordot
- if len(color_list_dot) == 1:
- color_list_dot = colordot*len(df.columns.to_numpy())
- if theme == 'dark':
- general.dark_bg()
- plt.subplots(figsize=dim)
- if errorbar:
- plt.bar(x=xbar, height=df.describe().loc['mean'], yerr=df.sem(), width=bw, color=color_list_bar, capsize=hbsize,
- zorder=0, alpha=valphabar, error_kw={'elinewidth': yerrlw, 'capthick': yerrcw})
- else:
- plt.bar(x=xbar, height=df.describe().loc['mean'], width=bw, color=color_list_bar,
- capsize=hbsize,
- zorder=0, alpha=valphabar)
- plt.xticks(xbar, df.columns.to_numpy(), fontsize=axtickfontsize, rotation=ar, fontname=axtickfontname)
- if axxlabel:
- _x = axxlabel
- if axylabel:
- _y = axylabel
- general.axis_labels(_x, _y, axlabelfontsize, axlabelfontname)
- # ylm must be tuple of start, end, interval
- if ylm:
- plt.ylim(bottom=ylm[0], top=ylm[1])
- plt.yticks(np.arange(ylm[0], ylm[1], ylm[2]), fontsize=axtickfontsize, fontname=axtickfontname)
- plt.yticks(fontsize=axtickfontsize, rotation=ar, fontname=axtickfontname)
- # add dots
- for cols in range(len(df.columns.to_numpy())):
- # get markers from here https://matplotlib.org/3.1.1/api/markers_api.html
- plt.scatter(x=np.linspace(xbar[cols]-bw/2, xbar[cols]+bw/2, int(df.describe().loc['count'][cols])),
- y=df[df.columns[cols]].dropna(), s=dotsize, color=color_list_dot[cols], zorder=1, alpha=valphadot,
- marker=markerdot)
- general.get_figure(show, r, figtype, 'bardot', theme)
|