import numpy as np import matplotlib.pyplot as plt import seaborn as sns import mpmath as mp from matplotlib.colors import LinearSegmentedColormap import copy import time import scipy.signal import gradio as gr def plot_heatmap(heatmap_data, plot_params): colormap = "erdc_iceFire" data = np.loadtxt(colormap + ".txt") cmap = LinearSegmentedColormap.from_list('my_colormap', data) plt.figure(figsize=plot_params['figsize']) sns.heatmap(heatmap_data, annot=plot_params['annot'], cmap=cmap, linewidths=0, cbar=True, vmin=0, vmax=plot_params['denominator'], cbar_kws={'label': plot_params['cbar_label']}) plt.xlabel(plot_params['xlabel'], size=16) plt.ylabel(plot_params['ylabel'], size=16) num_rows = heatmap_data.shape[0] if plot_params['maxyticks']==0: tick_spacing=1 else: tick_spacing = max(1, num_rows // plot_params['maxyticks']+1) # Generate tick positions and labels tick_positions = np.arange(0.5, num_rows, tick_spacing) tick_labels = np.arange(1, num_rows + 1, tick_spacing) # Set the ticks plt.yticks(tick_positions, tick_labels) if plot_params['vec2plot'] == 'both': # Assuming n is accessible, representing the number of cells in one chain n = heatmap_data.shape[0] // 2 num_ticks = 2 * n tick_labels = [str(i % n + 1) for i in range(num_ticks)] # Set y-ticks for every row tick_positions = np.arange(num_ticks) plt.yticks(tick_positions+0.5, tick_labels) plt.title(plot_params['title']) plt.tight_layout() plt.savefig(plot_params['filename'], dpi=plot_params['dpi']) plt.close()