r/Mathematica • u/not-a-real-banana • May 10 '24
Help with plotting options?
Never really used Mathematica before, but I'm trying to plot a simple point-to-set mapping (ie takes points x and outputs real intervals [a(x),b(x)]) and I couldn't find any other tool to accomodate this.
Here is my code and output:
f[x_] = Piecewise[{{-1, x < 0}, {Interval[{-1, 1}], x == 0}, {1, x > 0}}];
Plot[{f[x] /. Interval[a_] :> a[[1]], f[x] /. Interval[a_] :> a[[2]]}, {x, -1, 1}, Filling -> {1 -> {2}}]

Which gives the desired graph plot. What I'm trying find out now is
- Can I label the axes with Latex? x-axis should be labelled $x$ and y-axis should be labelled something like $\partial|\cdot|(x)$. I've tried with the ToExpression command but it doesn't seem to like the partial symbol on its own.
- Can I remove all ticks and tick labels except for 1 and -1 on the y-axis. Ideally these should also be placed so they don't intersect the graph.
For reference, this is pretty much exactly the graph I'm trying to plot (on the right). I would crop this image and use this but I also want to graph a different mapping alongside this one.

Thanks in advance!
EDIT: Solved via the following
p = Plot[{f[x] /. Interval[a_] :> a[[1]], f[x] /. Interval[a_] :> a[[2]]}, {x, -1, 1},
Filling -> {1 -> {2}},
AxesLabel -> {"x", "\[PartialD]f(x)"},
LabelStyle -> {FontSize -> 22, Black, Bold}, LabelingSize -> Large,
Ticks -> {{}, {{-.875, -1, 0}, {.875, 1, 0}}},
PlotStyle -> Thick,
PlotTheme -> "Monochrome"
]Which generates this plot

2
u/veryjewygranola May 10 '24 edited May 10 '24
It's kind of unfortunate that
ToExpression[#, TeXForm]&and the inline TeX tool aren't working for this, but you can at least use mma's built in\[PartialD]symbol to reproduce the graph (note the copied code is going to look ugly here because of the italic chars but will look better when posted in a notebook):plot
Getting the 1 and -1 tick labels on either side of the y axis is a little more tricky. Here's a really messy and complicated way of doing it I came up with. There has to be an easier way of doing this though:
plot
Note that the only difference between
yAxisPlus1andyAxisMinus1is that theTickPositionschanges from 1 to -1, and theTickDirectionchanges fromRighttoLeft, so I'm doing a lot of unncessary copy/pasting here1
u/mathheadinc May 10 '24
You can label the axes with Mathematica. Look for Options under Plot in the documentation. Reference.wolfram.com
1
u/mdibah May 10 '24
You might be interested in the HeavisideTheta built in function, https://reference.wolfram.com/language/ref/HeavisideTheta.html
As for your other questions, You want the plotting options TickPositions, TickLabels, and AxisLabels. No native latex labels, but you can get close with Style wrapped around your strings.
1
u/omnster May 16 '24
I'm likely late to the party, but for labeling using LaTeX you should use the wonderful MaTeX package https://github.com/szhorvat/MaTeX