def plot_scatter_line( t: Tuple[pd.Series, pd.Series, int, int, str, str, str, int, bool] ) -> NoReturn: X, y, file_name, target, feature, number_knots, dates = t model = ds.natural_cubic_spline(X=X, y=y, number_knots=number_knots) if dates: XX = X.astype(dtype='datetime64[ns]') else: XX = X fig, ax = ds.plot_scatter_line_x_y1_y2( X=XX, y1=y, y2=model.predict(X), figsize=figsize, labellegendy2=f'number knots = {number_knots}') ax.legend(frameon=False, loc='best') ax.set_title(label=f'{axis_title}\n' f'file: {file_name} ' f'column: {target}') ax.set_xlabel(xlabel=x_axis_label) ax.set_ylabel(ylabel=y_axis_label) ds.despine(ax=ax) fig.savefig( f'{graphics_directory}' f'/spline_' f'{file_name.strip(".csv")}_' f'{target}_{feature}_' f'{number_knots}.svg', format='svg')
def plot_recent_activity(activity: Optional[pd.DataFrame] = None) -> None: """ Line plot of number commits versus date. Parameters ---------- activity : pd.DataFrame """ figsize = (12, 6) title = 'Daily commits' y_label = 'Number of commits' x_label = 'Date' if activity is None: activity = recent_activity() commits = activity.reset_index().groupby('date').agg('sum') commits['low'] = commits['commits'].where(commits['commits'].between(0, 0)) fig, ax = ds.plot_line_x_y(X=commits.index, y=commits['commits'], figsize=figsize) ax.plot(commits['low'], marker='x', color='#cc3311') ax.xaxis.set_major_formatter(mdates.DateFormatter('%m-%d')) ax.set_ylabel(ylabel=y_label, fontweight='bold') ax.set_xlabel(xlabel=x_label, fontweight='bold') ax.set_title(label=title, fontweight='bold') median_value = commits['commits'].median() ax.axhline(y=median_value, color='#33bbee', label=int(median_value)) ax.legend(frameon=False) ds.despine(ax) fig.savefig(fname='commits_daily.svg', format='svg') ds.html_figure(file_name="commits_daily.svg") print(f'Commits by date\n{commits}\n') print(f"Median commits: {median_value.astype(dtype='int')}\n") print(f"Commits by ascending value\n{commits.sort_values(by='commits')}\n") print(f"Median commits: {median_value.astype(dtype='int')}")
def plot_scatter_y(t: pd.Series) -> None: y, feature = t fig, ax = ds.plot_scatter_y(y=y, figsize=figsize) ax.set_ylabel(ylabel=feature) ax.set_title(label='Time Series') ds.despine(ax) fig.savefig(fname=f'time_series_{feature}.svg', format='svg') ds.html_figure(file_name=f'time_series_{feature}.svg', caption=f'time_series_{feature}.svg')
def plot_graph(df: pd.DataFrame, columnx: str, columny: str, columnz: str, figsize: Tuple[int, int], dateformat: str, graphname: str, graphtitle: str, xaxislabel: str, yaxislabel: str) -> NoReturn: fig, ax = ds.plot_line_x_y(X=df[columnx], y=df[columnz], figsize=figsize) if dateformat: ax.xaxis.set_major_locator(DayLocator()) ax.xaxis.set_minor_locator(NullLocator()) ax.xaxis.set_major_formatter(DateFormatter(dateformat)) ax.xaxis.set_minor_formatter(NullFormatter()) ax.set_xlabel(xlabel=xaxislabel) ax.set_ylabel(ylabel=yaxislabel) ax.set_title(label=graphtitle) ds.despine(ax=ax) fig.savefig(fname=f'{graphname}.svg', format='svg')
def main(): start_time = time.time() global figsize, date_time_parser file_names, graph_file_names, abscissa_names, ordinate_names,\ ordinate_predicted_names, x_axis_label, y_axis_label, axis_title,\ figsize, column_names_sort, date_time_parser,\ date_formatter, alpha_value, function, output_url,\ header_title, header_id, parser = parameters() original_stdout = ds.html_begin(output_url=output_url, header_title=header_title, header_id=header_id) print('<pre style="white-space: pre-wrap;">') for (file_name, abscissa_name, ordinate_name, ordinate_predicted_name, date_time_parser, column_names_sort, date_formatter, graph_file_name) in zip(file_names, abscissa_names, ordinate_names, ordinate_predicted_names, date_time_parser, column_names_sort, date_formatter, graph_file_names): if date_time_parser == 'None': data = ds.read_file(file_name=file_name, sort_columns=column_names_sort, sort_columns_bool=True) else: data = ds.read_file(file_name=file_name, parse_dates=[abscissa_name], sort_columns=column_names_sort, sort_columns_bool=True) data[ordinate_predicted_name] = data[ordinate_name]\ .ewm(alpha=alpha_value).mean() fig, ax = ds.plot_scatter_line_x_y1_y2( X=data[abscissa_name], y1=data[ordinate_name], y2=data[ordinate_predicted_name], figsize=figsize) ax.set_title(label=axis_title, fontweight='bold') ax.set_xlabel(xlabel=x_axis_label, fontweight='bold') ax.set_ylabel(ylabel=y_axis_label, fontweight='bold') ds.despine(ax=ax) fig.savefig(fname=f'{graph_file_name}.svg', format='svg') ds.html_figure(file_name=f'{graph_file_name}.svg') ds.page_break() stop_time = time.time() ds.report_summary(start_time=start_time, stop_time=stop_time, read_file_names=file_names, targets=ordinate_names, features=abscissa_names) print('</pre>') ds.html_end(original_stdout=original_stdout, output_url=output_url)
def main(): invoicing = pd.read_csv(data_file_name, parse_dates=[date_column]) invoicing = calculate_cycle_time(df=invoicing, date_column=date_column, invoice_start_column=invoice_start_column, invoice_send_column=invoice_send_column, total_time_column=total_time_column) fig, ax = ds.plot_line_x_y(X=invoicing[date_column], y=invoicing[total_time_column]) ds.despine(ax) fig.suptitle(t=fig_title) ax.set_title(label=ax_title) ax.set_ylabel(ylabel=ylabel) ax.set_xlabel(xlabel=date_column) fig.savefig(fname='invoice_cycle_time.svg', format='svg')
print('Mean squared error') print(mse.round(3)) print() print('Root mean squared error') print(round(math.sqrt(mse), 3)) ds.page_break() # Scatter plot of predicted versus measured fig, ax = ds.plot_scatter_x_y(X=y_all, y=predicted, figsize=figsize) ax.plot([y_all.min(), y_all.max()], [y_all.min(), y_all.max()], marker=None, linestyle='-', color=colour2) ax.set_ylabel(ylabel=label_predicted) ax.set_xlabel(xlabel=label_measured) ax.set_title(label=title) ds.despine(ax) fig.savefig(fname=f'{graph_name}_scatter.svg', format='svg') ds.html_figure(file_name=f'{graph_name}_scatter.svg', caption=f'{graph_name}_scatter.svg') # Line plot of predicted versus measured fig, ax = ds.plot_line_line_y1_y2(y1=y_all, y2=predicted, figsize=figsize, labellegendy1=label_measured, labellegendy2=label_predicted) ax.legend(frameon=False) ax.set_title(label=title) ds.despine(ax) fig.savefig(fname=f'{graph_name}_lines.svg', format='svg') ds.html_figure(file_name=f'{graph_name}_lines.svg', caption=f'{graph_name}_lines.svg')
def main(): data_pumps = { 'x': [8.7, 11, 13.4, 14.9, 8.7, 8.9, 12.6, 10.7, 13.5, 16.4, 18.9, 16, 9], 'y': [17.9, 18.5, 17.4, 17.8, 14.9, 12.8, 11.7, 7.4, 8, 9.3, 9.7, 5, 5.1] } data_deaths = { 'x': [ 13.6, 9.9, 14.7, 15.2, 13.2, 13.8, 13.1, 11, 15.2, 11.1, 11.7, 12.3, 10.6, 14.6, 16.6, 9.5, 13.3, 15, 15.1, 10.9, 12.5, 11.8, 12.2, 13.9, 12.3, 11, 11, 13.5, 10.8, 12.2, 13.9, 12.5, 15.7, 12.9, 13, 13.7, 13.1, 13.4, 14.8, 13.2, 9.8, 12.5, 13.4, 14.4, 16, 10.9, 12.5, 15.8, 16.5, 11.2, 15.8, 11, 11.7, 11.5, 11.8, 13, 14.1, 14.8, 12.6, 14.6, 12.5, 14.5, 9.2, 17.9, 11.2, 9.5, 10.8, 16.1, 10.4, 13.7, 15.8, 12.2, 11.5, 15.4, 15.9, 10.2, 14, 16.5, 17.5, 13.8, 14.1, 14.7, 12.6, 11.7, 14.4, 15.2, 15.8, 13.9, 15.2, 13.2, 12.7, 15.1, 12.8, 13.6, 14, 15.4, 14.8, 10.3, 10.5, 9.9, 14.2, 13.6, 15, 15.7, 9.2, 16.8, 13.3, 10.6, 8.3, 13.4, 14.5, 16.8, 14.7, 10.3, 13.2, 9.1, 15.2, 8.4, 15.3, 13.3, 13.2, 12.6, 13.9, 13.5, 15.2, 11.6, 9.4, 11.4, 11.2, 11.9, 15, 13.6, 14.1, 10.5, 10.3, 13.8, 13.4, 12.6, 15.7, 13.8, 13.2, 15.1, 13.2, 14.6, 14.4, 15, 13.1, 13.4, 11.8, 16, 10.6, 14.6, 9.3, 14.5, 10.5, 14, 10.6, 10.6, 15.7, 11.8, 11.8, 11.6, 15.8, 10.7, 13.4, 11.2, 15.5, 14, 13.4, 14.6, 15.3, 14.5, 11.4, 12.5, 13.8, 10.6, 10.5, 14.8, 14.2, 13.3, 10.4, 12.5, 15, 10.6, 13.1, 10.1, 11.2, 12.9, 12.2, 12.4, 11.9, 11.5, 11.7, 12.5, 14.8, 14, 12.5, 9.2, 10.4, 12.7, 9.1, 8.3, 15.3, 11.2, 11.8, 12.7, 11.8, 12.2, 12.7, 13.6, 8.8, 12.2, 16.2, 12.8, 13.6, 12.7, 15, 13.9, 13.6, 12.5, 9.9, 17.6, 11.1, 16.7, 9.7, 13.4, 13.1, 13.7, 11.7, 13.1, 13.1, 12.3, 14.9, 11.5, 12.9, 11, 15.8, 12.9, 12.3, 9.8, 12.7, 12.7, 16, 11, 14.1, 11, 14.5, 15.6, 9.6, 15.5, 14.4, 11.4, 13.7, 11.4, 16, 9.9, 10.8, 12.6, 9.3, 13.8, 13.8, 14.7, 15.3, 14.1, 13.8, 11, 12.4, 14.8, 15, 15.4, 12.8, 11.3, 10.5, 11, 13.4, 10.3, 9.6, 14.5, 11.5, 12.7, 15, 12.3, 12.9, 15.3, 15.8, 13.1, 12.9, 15.3, 13, 12.5, 15.8, 14, 13, 13.9, 10.9, 16, 15.1, 13.5, 11.6, 10.7, 16.8, 13.9, 13.7, 13.3, 15.7, 15.5, 11, 15.5, 11.7, 12.4, 11.1, 9.6, 8.3, 14, 13.2, 15.3, 15.5, 15.4, 16.1, 12.4, 12.2, 15.1, 14, 9.6, 16.3, 12.6, 10.5, 14, 15.5, 11, 13.3, 13.9, 13.3, 12.7, 15.4, 15.7, 13.8, 11.7, 16.1, 12.6, 15.4, 16.3, 12.5, 15.7, 11.5, 14.2, 16.3, 13.6, 12.6, 11.7, 8.8, 10.9, 11.6, 13, 13.7, 11.1, 14.6, 10.4, 13.1, 11.9, 13.3, 9.9, 12.7, 9.3, 11.6, 13.1, 11.4, 13.6, 11.8, 16.3, 8.7, 15.7, 12.2, 14.8, 13.5, 15.7, 11.9, 12.5, 14.4, 12.2, 15.3, 11.5, 9, 10.8, 14.9, 13.2, 13.4, 14.4, 12.2, 12, 13.6, 8.8, 13.4, 12.6, 15.6, 12.5, 12.4, 12.4, 13.4, 12, 9.9, 12.1, 14.4, 15.7, 13.8, 11.4, 13.8, 15.6, 15, 14.1, 13.2, 13.3, 10.9, 12.1, 14, 11.3, 13.4, 13.5, 14.8, 13, 12.4, 12.3, 13.1, 14.8, 9.8, 14.1, 12, 16.1, 12.7, 14.7, 8.8, 10.5, 12.2, 11.7, 8.3, 12.4, 16.7, 15.7, 16.1, 14.3, 9.7, 13.3, 16.1, 14.4, 13.4, 14.5, 14.6, 13.7, 16.2, 16.3, 12.8, 13.4, 11.2, 11.6, 14.7, 9.4, 9.5, 15.7, 14.3, 14.2, 11.5, 15, 13.1, 11, 11.9, 13.5, 14.1, 10.9, 14.2, 10.4, 15.6, 11.3, 13, 13.6, 11.1, 14.6, 15.2, 13.4, 16.1, 14.3, 16.4, 12.6, 13.3, 11, 10.1, 15.6, 14.2, 13.4, 10.8, 13.2, 13.8, 11.4, 12.9, 13.6, 13.3, 12.2, 14.4, 8.9, 15.5, 14.3, 10, 13.2, 10.5, 9.5, 10.4, 10.9, 13.3, 12.6, 13.1, 11.6, 13.6, 13.4, 13.7, 10.7, 12.2, 14, 14.8, 15.1, 16.2, 15.3, 12.5, 14.7, 12.5, 10.9, 15.7, 11.7, 9.5, 13.3, 13.6, 13.4, 13.5, 11.1, 12.9, 12.8, 15.3, 12.8, 9.2, 14.4, 15.6, 10.4, 13, 13.2, 11, 13.5, 9.6, 14.5, 12.5, 10.7, 13.3, 9.4, 13.4, 13.5, 13.5, 13.6, 14.3, 9.6, 14.1, 12.9, 15.4, 13.8, 11.4, 12.4, 12.7, 13.6, 14.1, 15.1, 15.3, 14.7, 13.4, 12.3, 14.3, 12.4, 12.1, 12.4, 15.1, 17.3, 12.4, 15 ], 'y': [ 11.1, 12.6, 10.2, 10, 13, 8.9, 10.6, 11.9, 11.7, 9.6, 13.6, 11.5, 11.9, 10.6, 14.3, 10.7, 10.7, 10.2, 10, 9.8, 12, 11.8, 10.4, 12.8, 11.9, 11.9, 9.8, 13.3, 11.7, 13.6, 14, 11.6, 12.7, 9.9, 10.2, 11.4, 11.1, 11.1, 9.4, 13.2, 12.5, 12, 10.2, 11.6, 14.2, 12, 13.4, 12.4, 14.3, 8.6, 12.2, 9.8, 13.6, 12.3, 15.1, 13.9, 13.1, 10, 11, 12.9, 11.2, 8.7, 10.8, 7.2, 14.7, 10.7, 9.9, 14.1, 10.6, 9, 13.9, 11.8, 10.7, 11.2, 12.2, 11.9, 12.8, 11.4, 11.2, 8.9, 10.6, 11.5, 13.4, 10.4, 12.6, 17, 13.9, 12.7, 11.6, 12.9, 11.3, 13.2, 11.6, 13.2, 13.1, 13.3, 14.9, 11.4, 11.6, 12.3, 9.2, 12.5, 9.8, 12.4, 12, 11.4, 10.3, 11.6, 7.2, 13, 8.7, 11.4, 11.9, 11.4, 11.2, 13.2, 10, 7.4, 9.8, 12.4, 9.7, 11.5, 11, 12.5, 17, 11.1, 10.8, 9.6, 14.8, 10.2, 10.2, 11.5, 13.6, 11.2, 9.5, 12.7, 12.4, 11, 13.9, 8.9, 12.3, 10.1, 10.5, 11.4, 10.3, 14.1, 10.6, 8.8, 9.5, 14.4, 10.9, 10.6, 12.2, 11.5, 12.3, 12.8, 11.6, 11.7, 6.1, 11.2, 10.3, 11.1, 14, 11.7, 13.3, 11.5, 12.8, 10.7, 12.5, 16.2, 13.4, 8.8, 9.9, 11.2, 11.2, 11, 11, 10.8, 12, 12, 11.8, 10.6, 12, 9.9, 11.1, 11.5, 11.4, 11.7, 10, 11.3, 10.2, 11.4, 13.6, 11.5, 12.3, 12.7, 13.4, 12.3, 11.3, 9.2, 6.3, 7.1, 13.6, 11.4, 11.2, 11.3, 11.2, 13.6, 11.3, 13.4, 15.1, 11.3, 14.3, 11.6, 13.4, 10.2, 11.9, 12.7, 9.1, 13, 12.4, 7.3, 11.1, 14.4, 11, 13, 10.6, 10.1, 11.1, 11.8, 11.8, 11.9, 12.8, 12.6, 11.6, 11.2, 14, 10.3, 11.5, 11.8, 11.3, 12.1, 9.2, 11.9, 9.3, 11.7, 8.7, 11.3, 11.8, 11.1, 12.2, 9.9, 11.3, 11, 9.1, 11.9, 9.7, 11.6, 10.7, 13.8, 13.8, 10, 10, 12.4, 10.1, 11.3, 10.5, 10, 13.6, 13.5, 14.3, 9.8, 11.8, 11.2, 9.5, 11.4, 11.8, 12.3, 11.4, 10.7, 12, 14.8, 10.8, 9.1, 9.6, 13.9, 11.7, 12.1, 11.8, 11.2, 13, 13.4, 14.4, 14.6, 9.7, 14, 10.1, 12.6, 12.3, 12, 11.6, 14.6, 11.1, 9.6, 12.4, 11.2, 11.2, 11.1, 9.6, 11.4, 11.5, 10.9, 7.2, 13.3, 13, 9.3, 11.2, 7.3, 14.3, 13.7, 11.8, 11.7, 12.9, 10.9, 14.3, 10.6, 12.9, 12.8, 11.3, 11.2, 12.9, 13.6, 9.6, 10.7, 11.2, 13.9, 11.1, 10.5, 14.3, 11, 11.3, 14.4, 12.1, 12.9, 12.6, 12.1, 10.1, 11.2, 10.4, 11.2, 10.9, 14.7, 11.1, 11.2, 11.3, 11.8, 12.3, 11.6, 12.3, 14.2, 10.3, 12.2, 12.8, 10.6, 9.5, 12.3, 11, 11.5, 13.6, 14.4, 12.1, 12.2, 11.4, 14.1, 8.9, 12.9, 14.2, 12.8, 13.1, 14.1, 11.4, 10.8, 11.2, 8.8, 10.1, 11.9, 8.8, 12, 11.4, 14.6, 11.6, 12, 11, 12.8, 14.2, 12, 11.3, 11.4, 12.6, 11.4, 11.8, 13.6, 13.1, 12.9, 11.1, 10.9, 14.2, 11.3, 10.2, 13.1, 9.8, 13, 12, 10, 13.9, 10.8, 13, 12.5, 12, 11, 11.3, 14.8, 12.4, 13.2, 12.5, 10.6, 14.6, 14.2, 11.3, 10.1, 12.1, 12.3, 14.2, 13.6, 11.6, 13.2, 8.4, 7.2, 14.3, 10.5, 12.4, 12.9, 10, 10.4, 10.9, 9, 11.4, 13.9, 14.2, 14.4, 14.3, 11.9, 8.6, 12.2, 11.9, 10.8, 10.7, 11.6, 12.5, 13.4, 10.4, 10.4, 12.4, 12, 14.2, 8.9, 13.1, 16.5, 9.4, 11.2, 11.3, 11.5, 9.6, 13.1, 11.6, 11.4, 8.6, 10.4, 10.9, 10.4, 14.4, 15, 10.8, 12.1, 10.6, 12.6, 13.4, 12.5, 11.6, 10.6, 12.6, 11, 9.8, 11.1, 14.3, 11.4, 10.3, 12.1, 14.2, 10.4, 11.3, 14.3, 12.5, 10.6, 11.2, 14.6, 11, 11, 14.2, 10.5, 10.1, 13.1, 11.1, 12.5, 14.1, 13.3, 9.2, 10.1, 9.9, 11.4, 11.1, 11.4, 11.1, 14.7, 12.9, 12.6, 11.5, 14.8, 15.3, 10.3, 12.5, 11.1, 10.9, 16, 9.8, 11.3, 11.1, 12, 10.9, 11.2, 10.7, 11.9, 9.7, 11, 10.6, 10.6, 11.1, 12.5, 12.9, 11, 11.9, 11.1, 11, 9.1, 15.6, 10.6, 15.5, 13.8, 13.8, 12.7, 9.9, 11.4, 11.3, 11.5, 13.1, 10.1, 13.6, 10.2, 12.5, 11.9, 10.4, 11.6, 10.3, 11.5, 10.2, 11.6, 11.9, 12.5 ] } x_axis_label = 'X distance from lower left datum of map (m)' y_axis_label = 'Y distance from lower left datum of map (m)' axis_title = 'Broad Street Cholera Outbreak of 1854' file_graph = 'broad_street_cholera_outbreak.svg' output_url = 'broad_street_cholera.html' header_title = 'broad_street_cholera' header_id = 'broad-street-cholera' axis_subtitle = 'Soho, London, UK' legend1 = 'Deaths' legend2 = 'Pumps' figsize = (8, 6) ds.style_graph() original_stdout = ds.html_begin(output_url=output_url, header_title=header_title, header_id=header_id) deaths = pd.DataFrame(data=data_deaths) pumps = pd.DataFrame(data=data_pumps) fig, ax = ds.plot_scatter_scatter_x1_x2_y1_y2(X1=deaths['x'], X2=pumps['x'], y1=deaths['y'], y2=pumps['y'], figsize=figsize, markersize1=3, labellegendy2=legend2, colour1=colour1, colour2=colour2, markersize2=3, labellegendy1=legend1) ax.set_title(label=axis_title + '\n' + axis_subtitle) ax.set_ylabel(ylabel=y_axis_label) ax.set_xlabel(xlabel=x_axis_label) ax.legend(frameon=False) ds.despine(ax=ax) fig.savefig(fname=file_graph, format='svg') ds.html_figure(file_name=file_graph) ds.html_end(original_stdout=original_stdout, output_url=output_url)