def prev(self, event): ax = linear_curve_fitting_and_plotting(ind_filename2, dep_filename) plt.subplots_adjust(bottom=0.25) x_vals = df2[df2.columns[0]].values.tolist() y_vals = df2['Global Mean Sea Levels'].values.tolist() line_equation = stats_analysis.best_fit_regression_equation(x_vals, y_vals) correlation = str(stats_analysis.correlation(x_vals, y_vals)) r_squared = str(stats_analysis.r_squared(x_vals, y_vals)) ax.set_xlabel(df2.columns[0] + '\nCorrelation of Data: ' + correlation + '\nEquation of line fit: ' + line_equation + '\nR Squared Value: ' + r_squared) plt.draw()
def line1(self, _: Event) -> None: """Plot the scatter plot and line of best fit for the data in df1.""" ax = linear_curve_fitting_and_plotting(self._ind_filename1, self._dep_filename) plt.subplots_adjust(bottom=0.25) x_vals = self._df1[self._df1.columns[0]].values.tolist() y_vals = self._df1['Global Mean Sea Levels'].values.tolist() line_equation = stats_analysis.best_fit_regression_equation( x_vals, y_vals) correlation = str(stats_analysis.correlation(x_vals, y_vals)) r_squared = str(stats_analysis.r_squared(x_vals, y_vals)) ax.set_xlabel(self._df1.columns[0] + '\nCorrelation of Data: ' + correlation + '\nEquation of line fit: ' + line_equation + '\nR Squared Value: ' + r_squared) plt.draw()
def plot_graphs(df1: DataFrame, df2: DataFrame, df3: DataFrame) -> None: """Plotting the graphs using Plotly.""" fig, ax = plt.subplots() plt.subplots_adjust(bottom=0.2, right=0.8) ax.set_title(df1.columns[0] + '\nClick on legend line to toggle line on/off') line1, = ax.plot(df1[df1.columns[0]], df1['Global Mean Sea Levels'], lw=2, color='blue', label=df1.columns[0]) ###### # stats analysis ###### y_vals = df1[df1.columns[0]].values.tolist() x_vals = df1['Global Mean Sea Levels'].values.tolist() line_equation = stats_analysis.best_fit_regression_equation(x_vals, y_vals) correlation = str(stats_analysis.correlation(x_vals, y_vals)) r_squared = str(stats_analysis.r_squared(x_vals, y_vals)) ax.set_xlabel('Correlation of Data: ' + correlation + '\nEquation of line fit: ' + line_equation + '\nR Squared Value: ' + r_squared) # equation = stats_analysis.best_fit_regression_equation(x_vals, y_vals)[3:] # y_int = stats_analysis.y_intercept_of_best_fit(x_vals, y_vals) # slope = stats_analysis.slope_of_best_fit(x_vals, y_vals) # y_vals_act = [slope * x + y_int for x in x_vals] # line_reg = ax.plot(df1[df1.columns[0]], y_vals_act, lw=2, color='red') # line2, = ax.plot(df2[df2.columns[0]], df2['Global Mean Sea Levels'], # lw=2, color='red', label=df2.columns[0]) # line3, = ax.plot(df3[df3.columns[0]], df3['Global Mean Sea Levels'], # lw=2, color='green', label=df3.columns[0]) # positioning the legend leg = ax.legend(loc='lower right', fancybox=True, shadow=True, title='Legend') leg.get_frame().set_alpha(0.5) # sets opacity of the legend -- todo: could perhaps make # it so that it goes transparent when you're not hovering over it? # higher value in the brackets means less transparent # TODO: there's a better way to do this line1.set_marker('8') line1.set_linestyle('None') leg_line = leg.get_lines()[0] leg_line.set_picker(True) leg_line.set_pickradius(5) leg_line = line1 def onpick(event) -> None: # TODO: move this outside the function """ It's getting mad at me for not having a docstring but i honestly don't understand why the tutorials are saying to have this function in here """ # on the pick event, find the orig line corresponding to the # legend proxy line, and toggle the visibility legend_line = event.artist # original_line = lined[legend_line] original_line = line1 vis = not original_line.get_visible() original_line.set_visible(vis) # Change the alpha on the line in the legend so we can see what lines # have been toggled if vis: legend_line.set_alpha(1.0) else: legend_line.set_alpha(0.2) fig.canvas.draw() fig.canvas.mpl_connect('pick_event', onpick) plt.draw()