import matplotlib.pyplot as plt
import matplotlib.colors as mcolors


def plot_data(data, title, filename, show_plot=True):
    plt.figure(figsize=(10, 6))
    plt.imshow(data, cmap='viridis', interpolation='nearest')
    plt.colorbar(label='Value')
    plt.title(title)
    plt.savefig(filename)
    if show_plot:
        plt.show()
    plt.close()

def plot_data_with_custom_colormap(data, title, filename, show_plot=True):
    default_color_map = {
        0: '#ffff64', 10: '#ffff64', 11: '#ffff00', 12: '#aaf0f0', 20: '#dcf064', 30: '#c8c864', 40: '#006400',
        50: '#00a000', 60: '#00a000', 61: '#aac800', 62: '#003c00', 70: '#003c00', 71: '#005000', 72: '#285000',
        80: '#285000', 81: '#286400', 82: '#788200', 90: '#8ca000', 100: '#be9600', 110: '#966400', 120: '#966400',
        121: '#966400', 122: '#ffb432', 130: '#ffdcd2', 140: '#ffebaf', 150: '#ffc864', 151: '#ffd278', 152: '#ffebaf',
        153: '#00785a', 160: '#009678', 170: '#00dc82', 180: '#c31400', 190: '#fff5d7', 200: '#dcdcdc', 201: '#fff5d7',
        202: '#0046c8', 210: '#ffffff', 220: '#ffffff'
    }

    cmap = mcolors.ListedColormap([default_color_map[key] for key in sorted(default_color_map.keys())])
    norm = mcolors.BoundaryNorm(sorted(default_color_map.keys()), cmap.N)

    plt.figure(figsize=(10, 6))
    plt.imshow(data, cmap=cmap, norm=norm, interpolation='nearest')
    plt.colorbar(label='Land Cover Class')
    plt.title(title)
    plt.savefig(filename)
    if show_plot:
        plt.show()
    plt.close()