MCPcopy Create free account
hub / github.com/bsomps/OpenGeoPlotter / CustomPlotWindow

Class CustomPlotWindow

OGP_v11.py:3171–3300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3169
3170
3171class CustomPlotWindow(QWidget): # Custom plot window
3172 def __init__(self, json_file_path, data):
3173 super().__init__()
3174
3175 # Open and load the JSON file
3176 with open(json_file_path, 'r') as f:
3177 self.plot_info = json.load(f)
3178
3179 self.data = data
3180 self.extract_plot_limits_from_json()
3181
3182 self.figure = Figure()
3183 self.canvas = FigureCanvas(self.figure)
3184
3185 self.layout = QVBoxLayout(self)
3186 self.layout.addWidget(self.canvas)
3187
3188 self.setLayout(self.layout)
3189
3190 def extract_plot_limits_from_json(self):
3191 all_x_values = []
3192 all_y_values = []
3193 for polygon in self.plot_info.get('polygons', []):
3194 for point in polygon['points']:
3195 all_x_values.append(point[0])
3196 all_y_values.append(point[1])
3197 x_min, x_max = min(all_x_values), max(all_x_values)
3198 y_min, y_max = min(all_y_values), max(all_y_values)
3199 return (x_min, x_max), (y_min, y_max)
3200
3201
3202 def plot_custom(self, x, y, log_x, log_y, color_column=None, color_ramp=None, data_points=True):
3203 # Clear the current contents of the figure
3204 self.figure.clear()
3205
3206 # Create an axis
3207 ax = self.figure.add_subplot(111)
3208 x_limits, y_limits = self.extract_plot_limits_from_json()
3209 ax.set_xlim(x_limits)
3210 ax.set_ylim(y_limits)
3211
3212 # Plot the data
3213 if x and y and data_points:
3214 if color_column:
3215 if pd.api.types.is_numeric_dtype(self.data[color_column]):
3216 sc = ax.scatter(self.data[x], self.data[y], c=self.data[color_column], cmap=plt.get_cmap(color_ramp))
3217 cbar = plt.colorbar(sc)
3218 cbar.set_label(color_column)
3219 else:
3220 categories = self.data[color_column].unique()
3221 for category in categories:
3222 data_category = self.data[self.data[color_column] == category]
3223 ax.scatter(data_category[x], data_category[y], label=category, cmap=plt.get_cmap(color_ramp))
3224 ax.legend()
3225 else:
3226 ax.scatter(self.data[x], self.data[y])
3227
3228 # Use the plot information from the JSON file

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected