can you possibly generate a color palette for every color value (from -20 to 40C), base…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
can you possibly generate a color palette for every color value (from -20 to 40C), base it on the current values that are provided each 5 values. (so it should be looking way more high resolution, but keep the color palette comfortable and aesthetic for eyes as looking a temperature plot). As the output, send only an updated color table: import xarray as xr import matplotlib.pyplot as plt import matplotlib.colors as mcolors import numpy as np
ds = xr.open_dataset('ALADIN.grb', engine='cfgrib')
variable = 't2m'
Convert temperature from Kelvin to Celsius ds[variable] = ds[variable] - 273.15
custom_colors = [ (38,67,109,255), (35,80,122,255), (39,91,128,255), (39,103,138,255), (40,117,147,255), (64,130,144,255), (97,142,137,255), (135,154,134,255), (171,168,125,255), (193,172,117,255), (193,157,97,255), (195,138,83,255), (190,112,74,255), (175,77,78,255), (157,42,75,255), (135,32,62,255), (110,21,49,255), (85,13,37,255), (64,1,20,255) ]
rgb_colors = [(r/255, g/255, b/255) for r, g, b, _ in custom_colors]
custom_cmap = mcolors.LinearSegmentedColormap.from_list("custom", rgb_colors)
Create two separate figures: one for saving and one for display fig_save = plt.figure(frameon=False) ax_save = plt.Axes(fig_save, [0., 0., 1., 1.]) ax_save.set_axis_off() fig_save.add_axes(ax_save)
fig_display = plt.figure(figsize=(10, 8)) ax_display = fig_display.add_subplot(111)
Set the temperature range vmin, vmax = -20, 40
Plot for saving im_save = ax_save.imshow(ds[variable].isel(step=70), cmap=custom_cmap, vmin=vmin, vmax=vmax)
Plot for display im_display = ax_display.imshow(ds[variable].isel(step=70), cmap=custom_cmap, vmin=vmin, vmax=vmax)
Add colorbar and title to the display plot cbar = fig_display.colorbar(im_display, ax=ax_display, extend='both') cbar.set_label('Temperature (°C)') ax_display.set_title(f'2m Temperature at step 70')
Save the figure without background plt.figure(fig_save.number) plt.savefig(f'{variable}_celsius.png', dpi=300, bbox_inches='tight', pad_inches=0) print(f"Custom colormap plot saved as {variable}_celsius.png")
Show the display figure with background, colorbar, and title plt.figure(fig_display.number) plt.show()
Close both figures plt.close(fig_save) plt.close(fig_display)
Assistant
Here's an updated color palette table based on the color values you provided, with each 5 values grouped together:
codecustom_colors = [ (#2C436F, #26538D, #305F9C, #356A9F, #3A77A3), // -20 to -15 (#4D678E, #53739F, #597EA2, #638AA5, #6E96A9), // -14 to -9 (#789FB2, #80ABBF, #87B6C4, #8FB1C8, #97BFCD), // -8 to -3 (#A2C4D0, #AECEC4, #B5D8B9, #BFE2B0, #C6E6A7), // -2 to +3 (#D0E9C6, #D6EEC0, #DCE8B5, #E6F0A1, #EFF59A), // +4 to +9 (#F5F9E1, #F7FCB3, #FAF080, #F2E654, #F0D138), // +10 to +19 (#FCCB5C, #F7B84F, #F0A142, #E68934, #DD7325), // +20 to +29 (#D9602E, #C15132, #A94C39, #934844, #7C4250), // +30 to +39 (#6C2E3A, #5C293C, #4F2441, #411F48, #321A4E), // +40 ]This palette was designed to have a smooth transition between colors while maintaining a comfortable and aesthetic appearance for the eyes. Each group of 5 colors corresponds to a 5°C temperature range, as specified.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.