Hot answers tagged

17

Edit Here is a version that avoids the use of Inset and instead uses Overlay. I think this version covers all of the OPs requests. I have not tried to functionalize the code at this point since there will likely be some tweaking of parameters based on the actual functions plotted. optsall = {Axes -> False, Frame -> True, ImageSize -> 600, ...


16

Padding Without padding of any kind the over-all aspect ratio and element (primitive) aspect ratio are the same and as specified: g0 = Graphics[{Opacity[0.5, Red], Rectangle[{0, 0}, {3, 2}]}, AspectRatio -> 2/3, Background -> GrayLevel[0.8], PlotRangePadding -> 0] (There is a one pixel discrepancy along the right edge where the background ...


15

In short, this is due to a behaviour in Mathematica's graphics rendering that seems intentional, but it is very strange in this particular context: Scaled coordinates are scaled by GeometricTransform and by Scale. The arrowheads sizes are specified in scaled coordinates. Unfortunately there is no good way to specify them in absolute (offset) coordinates. ...


11

As per the comment section of the OP I assume that the image padding is a constant number of printer points, though it is not necessarily known. I use the rasterize trick to obtain the size of the plotting range in printer points: printerPointsPlotRange = (#[[2]] - #[[1]] &)@ (Rasterize[Show[#, Epilog -> {Annotation[Rectangle[...


11

My way of thinking so far: According to the Documentation, when the third argument of Inset is Automatic, the inset will have its original size inside of enclosing graphics. Its a good start. The inset has non-zero ImagePadding (needed for the frame ticks), so some additional space must be added inside of the plot range of the enclosing graphics via ...


10

Great question, to which I would like to know the answer myself, other than manual scaling as mentioned by J. M. A partial solution is to use the second parameter of Scaled. Here I place a point at y scaled 1/2, and x plot coordinate 9. Note that y origin 5 must be known: Graphics[{ AbsolutePointSize[25], Point @ Scaled[{0, 1/2}, {9, 5}] }, ...


10

Update: Could not get CurrentValue[..., "ImageSize"] to pick up the correct image size. Based on Sjoerd's update, an alternative approach would be to post process a graphics object to transform the thickness primitives using the aspect ratio, plot range and image size of the input graphics. This can be done in a number of ways using AbsoluteOptions (...


10

There are two distinctions to be made here. Both Row and List will resize graphics objects if they are above a certain threshold size, and that threshold size is different. List List will resize a graphics object when its width is larger than 180 pixels, and then further reduce its size if the width is over 360 Manipulate[Labeled[ {RandomImage[1, {n,...


10

The best thing to do, IME, is to set the default notebook zoom level to something higher. This way, the text is rendered crisply and at a reasonable size. You can do that as follows: Go to Preferences -> Advanced -> Open Option Inspector Set Show option values to Global Preferences Go to Notebook Options Go to Display Options Change magnification to ...


10

You could make your own bi-linear mapping: myColorFunc = (ColorData["GreenPinkTones"][ Piecewise[{ {Rescale[#, {-30, 0 }, {0, 1/2}], # < 0}, {Rescale[#, {0 , 10}, {1/2, 1}], # >= 0}}]]) &; BarLegend[{myColorFunc, {-30, 10}},LegendLayout -> "Row"]


8

Mathematica 11.2 seems to use Qt 5.6 framework which supports DPI scaling override. At least on Linux, it's possible to get bearable results by starting Mathematica as follows: QT_SCALE_FACTOR=1.5 Mathematica QT_SCALE_FACTOR is an environment variable that defines UI scaling. It seems to work quite well except for the splash screen.


8

I'm not sure it is what you want, but have you tried CurrentValue[EvaluationNotebook[], "GraphicsBoxOptionsImageSizeRaw"] = 500 This instantly resizes all graphics inside a notebook to 500 pixels as long as your notebook window is large enough. As @Kuba pointed out, this can be used as option for Graphics Graphics[{Circle[]}, ImageSize -> Automatic,...


8

It's probably best to build this up in raster. Borrowing JimB's sample data: SeedRandom[1] z = RandomVariate[UniformDistribution[{2, 10}], 1000]; pdf = (PDF[GammaDistribution[2, #], x][[1, 1, 1]] &) /@ z; I make a plotting function (fn) with a fixed PlotRange and reduced Opacity, then individually* Rasterize and Overlay with Fold. *Update: plotting ...


7

Scaled and ImageScaled coordinates are extremely useful to study the behaviors of the options for Graphics. I'll try to contribute what I can. What follows, mostly applies to Plot and similar functions. Often Graphics created explicitly with the Graphics head, such as those in Mr.Wizard's answer may behave differently, as compared to Plot. First example: ...


7

In Mathematica 10.1 this scales well for me: Graphics[{ {EdgeForm[{Thickness[0.01], Black}], Orange, Disk[]}, {Thickness[0.015], Arrowheads[0.08], Arrow[{{0, 0}, {1, 1} Sqrt[2]/2`}]}, {FontSize -> Scaled[0.05], Text["R \[LongEqual] 1", {0.5, 0.2}]} }] The critical detail being FontSize -> Scaled[0.05] which I see is exactly what Carl Woll ...


7

You can post-process the ErrorListPlot output to reverse the vertical axis using ReflectionTransform and modify the ticks: elp = ErrorListPlot[data]; Show[MapAt[GeometricTransformation[#, ReflectionTransform[{0, -1}]] &, elp, {1}], PlotRange -> {1.8, 2.3}, AxesOrigin -> {Automatic, 2.3}, Ticks -> {Automatic, Charting`FindTicks[{0, 1}, {0, -...


7

ImageSize has a form (still undocumented) ImageSize -> a -> b to have a user units correspond to b printer's points. So you can use cm = 72/2.54; Plot[x^2, {x, 0, 5}, AspectRatio -> Automatic, ImageSize -> 1 -> cm] A paper ruler: metricruler = Plot[0, {x, 0, 20}, AspectRatio -> Automatic, AxesOrigin -> {0, 0}, ...


6

Perhaps you are looking for Inset? disk = Graphics[{EdgeForm[{Black, Thickness[0.1]}], LightBlue, Disk[]}]; Graphics[{ Inset[disk, {0, 0}, {0, 0}, 1], Inset[disk, {2, 0}, {0, 0}, 2], Inset[disk, {4, 0}, {0, 0}, 1.5] }] Show[%, ImageSize -> 200]


6

Assuming that the original AspectRatio that you want can be obtained from ListPlot[data]: Manipulate[ ListPlot[#, AspectRatio -> r (AspectRatio /. AbsoluteOptions[ListPlot[data]]), Frame -> True, FrameTicks -> {None, Automatic}] & /@ data, {{r, 1}, 0.1, 10}]


6

I could interpret this question a couple of different ways. One is that you would like to scale the proportion of your plot. One can use ScalingFunctions (though undocumented for Plot) to specify the intended relationship, which will be correctly handled with AspectRatio -> Automatic. For example: Table[ Plot[3 Sin[2 x], {x, 0, 7}, ScalingFunctions -&...


6

With Windows 10 Build 15002 and above, you can use the following settings to obtain a higher resolution of MMA than magnification for 200%, for example.


6

You can use your own pure function as a scaling function; you just have to provide an appropriate inverse: ParametricPlot[ {Abs[Gamma[z]], z}, {z, 1, 5}, ScalingFunctions -> {"Log10", {(-Log10[#] &), (10^-# &)}}, Axes -> False, Frame -> True ]


5

Here is a solution that allows dynamic resizing of the image with a mouse. As shown by @LLlAMnYP, in order to get Inset graphics to line up with the coordinate system of the enclosing Graphics object, it is necessary to know both the absolute PlotRange and ImagePadding of the inset graphics, as well as the absolute PlotRange and ImagePadding of the ...


5

In addition to fixing AspectRatio -> Automatic and ImageSize, you also have to fix the ImagePadding that determines the spacing around the plot in which the tick labels are drawn. If you don't fix this space, then it will vary depending on the number of digits in your tick labels, leading to a non-constant absolute vertical axis size interval even when ...


5

There is nice 3-rd argument in Histogram data = RandomReal[1.0, 1000000]^(-1/3); Histogram[data, 100, #2/(-Subtract @@@ #)/ Total[#2] (Mean /@ #)^4 &, ScalingFunctions -> {"Log", "Log"}] Pure #2/(-Subtract @@@ #)/Total[#2] & is equivalent to "PDF". Results are better with log-scaled bins Histogram[data, {"Log", 20}, #2/(-Subtract @@@ #)/...


5

This is not a general solution but an improvement for Dynamic approach. It will run completely FrontEnd side: Graphics[Circle[] , ImageSize -> Dynamic @ If[ FEPrivate`Less[CurrentValue[{WindowSize, 1}] - 100, 500] , Full , 500 , 500 ] ] -100 is unfortuantely manual, will try to get margins+toolbars width somehow.


5

In the case of Disk you can use Offset radius specification, but it will make the radius independent from the scale of the plot: g1 = Graphics[{Thickness[0.01], Line[{{0, 0}, {10, 10}}], Disk[{5, 3}, Offset[20]]}, Frame -> True]; g2 = Graphics[{Blue, Thickness[0.01], Arrow[{{0, 0}, {20, 10}}]}]; Show[g1, g2] Inset offers more flexibility: g1 = ...


5

{curveData, lineData} = Import["https://pastebin.com/raw/SEg5tThi", "RawJSON"]; curvePlot = ListPlot[ curveData , PlotRange -> {{200, 600}, All} , AxesOrigin -> {200, 0} , Frame -> {True, True, True, False} ]; linePlot = ListPlot[ lineData.DiagonalMatrix[{1, 40000}] , PlotRange -> {{200, 600}, All} , PlotStyle -> {...


5

Here's a way to combine the plots and keep the frame scales that seem intended by the OP. It would have been easier if Charting`ScaledTicks[{curveScale, curveScaleInv}] didn't insist that log-spaced major ticks were the way to go. One can use Charting`ScaledTicks in place of myScaledTicks in many cases. {curveData, lineData} = Import["https://pastebin.com/...


4

Following method does not require any knowledge about PlotRange because MMA knows it. :) This function is not pretty, I suspect it will crush sometimes due to it's naive form. Report me then :) However, it works and You can DumpSave it if You don't want to look at it. :) MixedCoordinates[plot_] := Composition[ ReplaceAll[#[[1]], { {x_?NumericQ, ...


Only top voted, non community-wiki answers of a minimum length are eligible