diff --git a/mesaPlot/plot.py b/mesaPlot/plot.py index 396cfcd..6fc439e 100644 --- a/mesaPlot/plot.py +++ b/mesaPlot/plot.py @@ -5335,6 +5335,8 @@ def plotKip3( zone_frac=1.0, num_zones=None, mix_hatch=False, + mix_hatch_patterns = ["//", "...", "\\\\", "||", "x", "*"], + mix_hatch_colors = ['chartreuse', 'purple', 'red', 'gold', 'brown', 'gray'], hatch_color="black", hatch_func=None, zaxis_norm=False, @@ -5487,6 +5489,11 @@ def plotKip3( mix_data = self._rebinKipDataX( mix_data, data_x[modInd], lin_x, nan=True, nan_value=1 ) + + if yaxis_norm: + data_y_min, data_y_max = np.min(data_y), np.max(data_y) + if data_y_max > data_y_min: + data_y = (data_y - data_y_min) / (data_y_max - data_y_min) else: show_mix = False @@ -5612,18 +5619,37 @@ def plotKip3( if show_mix: mixCmap, mixNorm = self._setMixRegionsCol(kip=True) if mix_hatch: - plt.rcParams["hatch.color"] = hatch_color - ax.contourf( + from matplotlib.patches import PathPatch + + # Create a filled contour plot (only to extract paths) + filled_contours = ax.contourf( lin_x, data_y, mix_data.T, - colors="none", + colors='none', alpha=0.0, - norm=mixNorm, - hatches=["//", "-", "x", "+", "\\", "/"], + hatches=mix_hatch_patterns, antialiased=True, ) - ax.contour(lin_x, data_y, mix_data.T, colors=hatch_color, norm=mixNorm) + + # manage hatches and colors + num_collections = len(filled_contours.collections) + patterns = (mix_hatch_patterns * (num_collections // len(mix_hatch_patterns) + 1))[:num_collections] + colors = (mix_hatch_colors * (num_collections // len(mix_hatch_colors) + 1))[:num_collections] + + # applying hatches and colors dynamically + for collection, hatch, color in zip(filled_contours.collections, patterns, colors): + for path in collection.get_paths(): + patch = PathPatch( + path, + edgecolor=color, + facecolor='none', + hatch=hatch, + linewidth=0.5, + alpha=1.0, + ) + ax.add_patch(patch) # Add the patch to the axes + ax.contour(lin_x, data_y, mix_data.T, colors=mix_hatch_colors, norm=mixNorm) else: ax.imshow( mix_data.T,