Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def draw_linechart(w,h,v_lines, title, x_label, y_label, rot, legend, sort, sort_array, grid, sci, save, ylim=[]):
- fig = plt.figure(figsize=(w,h))
- #title and axis labels
- plt.title(title,fontsize=20)
- plt.ylabel(y_label)
- plt.xlabel(x_label)
- if(len(ylim) == 2):
- axes = plt.gca()
- axes.set_ylim(ylim)
- #scientific notation
- if sci:
- plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0), useMathText=True)
- #ticks angle (0=horizontal, 90=vertical)
- plt.xticks(rotation=rot)
- #grid
- if grid:
- plt.grid(color='grey', linestyle='--', linewidth=0.5)
- for i in range(0, len(v_lines)):
- DS = v_lines[i]['dataset']
- x = v_lines[i]['x_att']
- y = v_lines[i]['y_att']
- if sort:
- DS["sort"] = DS_gb.apply(lambda row: get_ind(sort_array, row["borough"]),axis=1)
- DX = DS.sort_values("sort", ascending=True)
- xnew = np.linspace(DS[x].min(),DS[x].max(),300) #300 represents number of points to make between T.min and T.max
- ynew = spline(DS[x],DS[y],xnew)
- #plotting the line
- plt.plot(xnew, ynew, color=v_lines[i]['colore'],
- label=v_lines[i]['label'], marker=v_lines[i]['marker'],
- linestyle=v_lines[i]['linestyle'])
- if legend:
- plt.legend(bbox_to_anchor=(1,0.7), loc="center left")
- if save:
- plt.savefig(title+".png", bbox_inches="tight")
- else:
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement