I would like to know if that is possible to reproduce a color palette from an image.
Here is an example. Pages 1 and 3 show a rainbow palette in the figure legend.
The software is proprietary and has very little room for customization. I would like to regenerate the legend by R (or any other programming language, e.g. python) but retain the scale/ range of the colors.
I recognize that some color picker tools are available. However, the resolution of the palette is quite low, and often 3-4 colors are displayed in the same row. I am not sure which color I should pick in the raster image.

You can use OpenCV (cv2) library and export the color data as a histogram. It's also possible to apply a mask to a certain area of the image to extract the color data from that part.
For examples/documentation you can find more here: Histograms - 1 : Find, Plot, Analyze and this one might suite you a bit more where it shows how to create 2D histograms: Histograms - 3 : 2D Histograms
Hope this helps!