Consider the following figure:
I would like to plot a test function
func[ma_]=1000*ma^5
over it. Is it possible somehow to do?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityYou can use Prolog
and Inset
to position the image behind the plot, but some calibration is needed to get correct coordinates.
First, calibrate the image by determining the location of the bottom-left and top-right corners of the plot.
img = Import["https://i.stack.imgur.com/rUBAY.png", "Image",
ImageResolution -> 72];
imageData = ImageData[img, DataReversed -> True];
Manipulate[
Graphics[{Raster[imageData, {{0, 0}, ImageDimensions[img]}]},
ImageSize -> 500], {{bottomLeft, {0, 0}}}, {{topRight, {300,
300}}}, {{bottomLeft, {0, 0}}, Locator}, {{topRight, {300, 300}},
Locator}]
Then assign the corresponding $x$ and $y$ range*, and use this data to calculate the correct aspect ratio and image scaling.
bottomLeft = {182, 151};
topRight = {1687, 966};
{xRange, yRange} = {{0, 3}, {-3, 7}};
aspectRatio = 1/Divide @@ (topRight - bottomLeft);
scaling = Abs[Subtract @@ xRange]*
First@ImageDimensions[img]/First@(topRight - bottomLeft);
Finally, use Plot
* to draw your function. Make sure the axes are properly aligned, then use Frame -> False
and remove SetAlphaChannel
to get the final image.
func[ma_] := 1000 * ma^5;
Plot[Log10[func[ma]], {ma, xRange[[1]],
xRange[[2]]}, {PlotRange -> {xRange, yRange},
PlotStyle -> {Thick, Red},
Prolog -> {Inset[
SetAlphaChannel[img, .3], {xRange[[1]], yRange[[1]]}, bottomLeft,
scaling]}, AxesOrigin -> {0, -3}, AspectRatio -> aspectRatio,
Axes -> False, ImageSize -> 500, Axes -> True, ImagePadding -> 50,
PlotRangeClipping -> False, Frame -> True}]
* Due to plot coordinate system, it is more convenient to use Plot[Log10[ ...]]
instead of LogPlot[]
.
figure
, you mean this is an image of a plot only available as an image file? $\endgroup$