I wish to imitate the opacity plot as shown below:
Edit2: (ref: https://www.wolfram.com/mathematica/new-in-9/3d-volumetric-image-processing/edit-color-function-palette-for-image3d.html)
Here is what I am up to now:
makeColorFn[colors_, opacities_, vars_] :=
Transpose[{vars, MapThread[Append, {colors, opacities}]}] /.
body_ :> (Blend[body, #] &)
colors =
{RGBColor[0.761959, 0.470832, 0.940597], RGBColor[0.927848, 0.742785, 0.615138],
RGBColor[0.929162, 0.95034, 664815], RGBColor[0.431296, 0.709773, 0.927077]};
opacities = {0.632, 0.938, 0.906, 0.864};
keys = {0, 1/3, 2/3, 1};
mesh =
ParametricPlot[{v, u}, {v, 0, 1}, {u, 0, 1},
MeshFunctions -> {#2 &, #1 &},
MeshShading -> {{Gray, White}, {White, Gray}}, Mesh -> {20, 20},
FrameLabel -> {"Intensity", Opacity},
ColorFunction -> "",
PlotRange -> {0, 1}]
The above code was taken from here and gives me the following plot:
If I now plot the color function on top of this background,
ListLinePlot[Transpose[{keys, opacities}],
Prolog -> mesh[[1]],
Mesh -> All, MeshStyle -> Directive[PointSize[Large], colors],
PlotRange -> Full, Filling -> Axis,
ColorFunction -> ColorTransferFunction[colors, opacities, keys],
Frame -> True, FrameLabel -> {"Intensity", "Opacity"}]
And the corresponding result is:
Firstly, I need the plot to be scaled accordingly as in fig 2.
Secondly, I want the control points to be colored according to the colors and opacities at those points and not a single color (blue) as I have got.
[Optional: How can I remove the checkered background above the control points?]
Update
I have updated the code for plotting as follows:
DynamicModule[{points = Transpose[{keys, opacities}]},
ListLinePlot[points,
Epilog -> {PointSize[0.03], Point[points, VertexColors -> colors]},
Prolog -> mesh[[1]],
PlotRange -> {{0., 1.}, {0., 1.}},
Frame -> True,
FrameLabel -> {"Intensity", "Opacity"},
Filling -> Axis,
ColorFunction -> ColorTransferFunction[colors, opacities, keys]]]
and got the result: