Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. def draw_linechart(w,h,v_lines, title, x_label, y_label, rot, legend, sort, sort_array, grid, sci, save, ylim=[]):
  2.     fig = plt.figure(figsize=(w,h))
  3.     #title and axis labels
  4.     plt.title(title,fontsize=20)
  5.     plt.ylabel(y_label)
  6.     plt.xlabel(x_label)
  7.    
  8.     if(len(ylim) == 2):
  9.         axes = plt.gca()
  10.         axes.set_ylim(ylim)
  11.    
  12.     #scientific notation
  13.     if sci:
  14.         plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0), useMathText=True)
  15.    
  16.     #ticks angle (0=horizontal, 90=vertical)
  17.     plt.xticks(rotation=rot)
  18.    
  19.     #grid
  20.     if grid:
  21.         plt.grid(color='grey', linestyle='--', linewidth=0.5)
  22.        
  23.     for i in range(0, len(v_lines)):
  24.         DS = v_lines[i]['dataset']                      
  25.         x = v_lines[i]['x_att']
  26.         y = v_lines[i]['y_att']
  27.  
  28.         if sort:
  29.             DS["sort"] = DS_gb.apply(lambda row: get_ind(sort_array, row["borough"]),axis=1)
  30.             DX = DS.sort_values("sort", ascending=True)
  31.        
  32.     xnew = np.linspace(DS[x].min(),DS[x].max(),300) #300 represents number of points to make between T.min and T.max
  33.  
  34.      ynew = spline(DS[x],DS[y],xnew)
  35.        
  36.         #plotting the line
  37.      plt.plot(xnew, ynew, color=v_lines[i]['colore'],
  38.                  label=v_lines[i]['label'], marker=v_lines[i]['marker'],
  39.                  linestyle=v_lines[i]['linestyle'])
  40.     if legend:
  41.          plt.legend(bbox_to_anchor=(1,0.7), loc="center left")  
  42.     if save:
  43.         plt.savefig(title+".png", bbox_inches="tight")
  44.     else:
  45.         plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement