@R.M hello; I am interested in your post mathematica.stackexchange.com/questions/2058/… I would like to write a function which could post process a given ContourPlot or DensityPlot and add a color bar as you did in that post but with the proper scaling
for instance if I replace Sin[..] by 2 Sin[..] in your example, the scaling on the color bar will be wrong.
so the challenge is extracting the range from the previous plot.
@R.M I don't think so, but Experimental`OptimizeExpression is IMO one of the best-known undocumented functions, so it gets mentioned everywhere. Feel free to ask a question if you want to get some quasi-official documentation on it on the site.
@R.M oh, Daniel mentioned it here on SO, apparently. (I wasn't on SO, so I missed that.)
There are several ways in which you can get the min/max values from a plot. For a simple line plot, it might be as simple as inspecting the FullForm and picking out the max value from the Line[...] part.
But a general way to do this would be using EvaluationMonitor to sow the values of the function, then take the min/max of that and feed it to the modified colorbar function