def display_object(coordinates): print("display_object() START ") # fig = plt.figure(1, figsize=(10, 5), dpi=90) # ax = fig.add_subplot(111) fig, ax = plt.subplots(1, figsize=(10, 5)) latitude_start = -90 latitude_end = 90 longitude_start = 0 longitude_end = 360 break_between = 30 break_between_minor = 10 ax.set_xlim(longitude_start, longitude_end) ax.set_ylim(latitude_start, latitude_end) ax.set_xticks(np.arange(longitude_start, longitude_end, break_between_minor), minor=True) ax.set_yticks(np.arange(latitude_start, latitude_end, break_between_minor), minor=True) ax.set_xticks(np.arange(longitude_start, longitude_end, break_between)) ax.set_yticks(np.arange(latitude_start, latitude_end, break_between)) ax.grid(which='both') # push grid lines behind the elements ax.set_axisbelow(True) for c in coordinates: #plt.scatter(c[0], c[1], marker='o', s=1) plt.fill(c[0], c[1]) plt.show()
def draw(self): if self.needRefresh: color_intensity = 1. - 0.5 * self.meanDensity() rgb_val = [color_intensity, color_intensity, color_intensity] if self.plot_h['meanPatch'] is None: polygonList = plt.fill(self.vertices_x, self.vertices_y, color=rgb_val) self.plot_h['meanPatch'] = polygonList[0] else: self.plot_h['meanPatch'].set_color(rgb_val) self.needRefresh = 0
def draw_rectangle(center, theta, height, width, color, edge_color, display_option): x = center(1) y = center(2) x_v = [x ,x + height, x + height, x, x] y_v = [y , y, y + width , y + width, y] # rotate angle theta R = [] R[1,:]=x_v - x R[2,:]=y_v - y XY = [math.cos(theta) - math.sin(theta), math.sin(theta), math.cos(theta)]*R; XY[1,:] = XY[1,:] + x XY[2,:] = XY[2,:] + y R = rotate(height / 2, width / 2, theta) X = XY[1,:] - R[1] Y = XY[2,:] - R[2] RectLines = [[X[1],Y[1],X[2],Y[2]],[X[2],Y[2],X[3],Y[3]], [X[3],Y[3],X[4],Y[4]],[X[4],Y[4],X[5],Y[5]]] if (display_option): rect = matplotlib.fill(X, Y, color) set(rect, 'FaceColor', color, 'EdgeColor', edge_color, 'LineWidth', 1)
def graph_intervals( X_test, y, best_model, actual_label, lower_bound_label, upper_bound_label, interval_label, title, model_params, n=100, # x_axis_col="store_order_id", ): # Don't show plots. y_interval_predicted = best_model.predict(X_test) X = X_test.copy() pd.options.mode.chained_assignment = None X[lower_bound_label] = y_interval_predicted[0, :, 0] X[upper_bound_label] = y_interval_predicted[0, :, 1] # X[lower_bound_label] = best_model.forest.predict(X_test) # X[upper_bound_label] = best_model.forest.predict(X_test) X[actual_label] = y pd.options.mode.chained_assignment = "warn" plt.rcParams["figure.figsize"] = [9, 16] plt.rcParams["figure.dpi"] = 400 fig = plt.figure() X_sample_w_index = X.sample(n=n).sort_values(by=[actual_label]) X_sample = X_sample_w_index.reset_index() plt.plot(X_sample.index, X_sample[actual_label], "b.", markersize=10, label=u"Observations") plt.plot(X_sample.index, X_sample[lower_bound_label], "k-") plt.plot(X_sample.index, X_sample[upper_bound_label], "k-") plt.fill( np.concatenate([X_sample.index, X_sample.index[::-1]]), np.concatenate( [X_sample[upper_bound_label], X_sample[lower_bound_label][::-1]]), alpha=0.2, fc="b", ec="None", label=interval_label, ) contains = (len(X[(X[lower_bound_label] <= X[actual_label]) & (X[actual_label] <= X[upper_bound_label])].index) / len(X.index)) over_estimates = len( X[(X[lower_bound_label] > X[actual_label])].index) / len(X.index) under_estimates = len( X[(X[upper_bound_label] < X[actual_label])].index) / len(X.index) median_interval_width = (X[upper_bound_label] - X[lower_bound_label]).median() score = interval_score(y, y_interval_predicted) scores = (r"contains={0:.0%}" + "\n" + r"underestimates={1:.0%}" + "\n" + r"overestimates={2:.0%}" + "\n" + r"med_interval_width={3:.2f}" + "\n" + r"score={4:.2f}").format(contains, over_estimates, under_estimates, median_interval_width, score) extra = plt.Rectangle((0, 0), 0, 0, fc="w", fill=False, edgecolor="none", linewidth=0) plt.legend([extra], [scores], loc="upper left") plt.title(title + ":" + model_params) plt_filename = title + ":" + model_params + ".png" plt.savefig(plt_filename, bbox_inches="tight") plt.close(fig) return plt_filename