Package: easy-mpl
Matplotlib is great library which offers huge flexibility due to its object oriented
programming style. However,mostof the times, we the users don't need that
much flexibiliy and just want to get things done as quickly as possible. For example
why should I write at least three lines to plot a simple array with legend when same
can be done in one line and my purpose is just to view the array. Why I can't simply
doplot(data)orimshow(img). This motivation gave birth to this library.easy_mplstands for easy maplotlib. The purpose of this is to ease the use of
matplotlib while keeping the flexibility of object oriented programming paradigm
of matplotlib intact. Using these one liners will save the time and will not hurt.
Moreover, you can swap most functions of this library with that of matplotlib and
vice versa. For more detailed description seeintroductionInstallationThis package can be installed using pip from pypi using following commandpip install easy_mplAPIplotbar_chartregplotimshowhistpiescattercontourdumbbell_plotridgeparallel_coordinatesspider_plottaylor_plotlollipop_plotcircular_bar_plotboxplotviolin_plotUsageFor a wide range of usage examples seegallery of examplesplotimportnumpyasnpfromeasy_mplimportplotx=np.random.randint(2,10,10)plot(x,'--o',color=np.array([35,81,53])/256.0,ax_kws=dict(xlabel="Days",ylabel="Values"))scatterimportnumpyasnpfromeasy_mplimportscatterimportmatplotlib.pyplotaspltx=np.random.random(100)y=np.random.random(100)ax,_=scatter(x,y,colorbar=True)assertisinstance(ax,plt.Axes)imshowimportnumpyasnpfromeasy_mplimportimshowdata=np.random.random((4,10))imshow(data,cmap="YlGn",xticklabels=[f"Feature{i}"foriinrange(data.shape[1])],grid_params={'color':'w','linewidth':2},annotate=True,colorbar=True)bar_chartfromeasy_mplimportbar_chartbar_chart([1,2,3,4,4,5,3,2,5],['a','b','c','d','e','f','g','h','i'],bar_labels=[11,23,12,43,123,12,43,234,23],cmap="GnBu",sort=True)histimportnumpyasnpfromeasy_mplimporthistdata=np.random.randn(1000)hist(data,bins=100)lollipop_plotimportnumpyasnpfromeasy_mplimportlollipop_ploty=np.random.randint(0,10,size=10)lollipop_plot(y,sort=True,title="sort")dumbbell_plotimportnumpyasnpfromeasy_mplimportdumbbell_plotst=np.random.randint(1,5,10)en=np.random.randint(11,20,10)dumbbell_plot(st,en)regplotimportnumpyasnpfromeasy_mplimportregplotrng=np.random.default_rng(313)x=rng.uniform(0,10,size=100)y=x+rng.normal(size=100)regplot(x,y,line_color='black')ridgeimportnumpyasnpfromeasy_mplimportridgedata=np.random.random((100,3))ridge(data)piefromeasy_mplimportpieexplode=(0,0.1,0,0,0)pie(fractions=[0.2,0.3,0.15,0.25,0.1],explode=explode)contourimportnumpyasnpfromeasy_mplimportcontour_x=np.random.uniform(-2,2,200)_y=np.random.uniform(-2,2,200)_z=_x*np.exp(-_x**2-_y**2)contour(_x,_y,_z,fill_between=True,show_points=True)circular_bar_plotimportnumpyasnpfromeasy_mplimportcircular_bar_plotdata=np.random.random(50,)circular_bar_plot(data,text_kws={"fontsize":16})parallel_coordinatesimportnumpyasnpimportpandasaspdfromeasy_mplimportparallel_coordinatesynames=['P1','P2','P3','P4','P5']# feature/column namesN1,N2,N3=10,5,8N=N1+N2+N3categories_=['a','b','c','d','e','f']y1=np.random.uniform(0,10,N)+7y2=np.sin(np.random.uniform(0,np.pi,N))y3=np.random.binomial(300,1/10,N)y4=np.random.binomial(200,1/3,N)y5=np.random.uniform(0,800,N)# combine all arrays into a pandas DataFramedata_df=pd.DataFrame(np.column_stack((y1,y2,y3,y4,y5)),columns=ynames)# using continuous values for categoriesparallel_coordinates(data_df,names=ynames,categories=np.random.randint(0,5,N))spider_plotimportpandasaspdfromeasy_mplimportspider_plotdf=pd.DataFrame.from_dict({'summer':{'a':-0.2,'b':0.1,'c':0.0,'d':0.1,'e':0.2,'f':0.3},'winter':{'a':-0.3,'b':0.1,'c':0.0,'d':0.2,'e':0.15,'f':0.25},'automn':{'a':-0.1,'b':0.3,'c':0.15,'d':0.24,'e':0.18,'f':0.2}})spider_plot(df,xtick_kws={'size':13},frame="polygon",color=['b','r','g','m'],fill_color=['b','r','g','m'])taylor_plotimportnumpyasnpfromeasy_mplimporttaylor_plotnp.random.seed(313)observations={'site1':np.random.normal(20,40,10),'site2':np.random.normal(20,40,10),'site3':np.random.normal(20,40,10),'site4':np.random.normal(20,40,10),}simulations={"site1":{"LSTM":np.random.normal(20,40,10),"CNN":np.random.normal(20,40,10),"TCN":np.random.normal(20,40,10),"CNN-LSTM":np.random.normal(20,40,10)},"site2":{"LSTM":np.random.normal(20,40,10),"CNN":np.random.normal(20,40,10),"TCN":np.random.normal(20,40,10),"CNN-LSTM":np.random.normal(20,40,10)},"site3":{"LSTM":np.random.normal(20,40,10),"CNN":np.random.normal(20,40,10),"TCN":np.random.normal(20,40,10),"CNN-LSTM":np.random.normal(20,40,10)},"site4":{"LSTM":np.random.normal(20,40,10),"CNN":np.random.normal(20,40,10),"TCN":np.random.normal(20,40,10),"CNN-LSTM":np.random.normal(20,40,10)},}# define positions of subplotsrects=dict(site1=221,site2=222,site3=223,site4=224)taylor_plot(observations=observations,simulations=simulations,axis_locs=rects,plot_bias=True,cont_kws={'colors':'blue','linewidths':1.0,'linestyles':'dotted'},grid_kws={'axis':'x','color':'g','lw':1.0},title="mutiple subplots")boxplotimportpandasaspdfromeasy_mplimportboxplotfromeasy_mpl.utilsimport_rescalef="https://raw.githubusercontent.com/AtrCheema/AI4Water/master/ai4water/datasets/arg_busan.csv"df=pd.read_csv(f,index_col='index').iloc[:,0:10]forcolindf.columns:df[col]=_rescale(df[col])boxplot(df,fill_color="GnBu",notch=True,patch_artist=True,medianprops={"color":"black"})violin_plotimportmatplotlib.pyplotaspltimportpandasaspdfromeasy_mplimportviolin_plotfromeasy_mpl.utilsimport_rescalef="https://raw.githubusercontent.com/AtrCheema/AI4Water/master/ai4water/datasets/arg_busan.csv"df=pd.read_csv(f,index_col='index').iloc[:,0:10]forcolindf.columns:df[col]=_rescale(df[col])axes=violin_plot(df,show=False)axes.set_facecolor("#fbf9f4")plt.tight_layout()plt.show()Code Structure