5
$\begingroup$

Is it possible to change the location of number labels on the x-axis? On the plot below, created with Show (3 Plots, 6 ListLinePlots), I would like to move the Temperature tick labels (5, 10, etc.) from below the x-axis to above that axis.

I can share my code if necessary, but mainly I would like to know if there is a built-in function to specify label position relative to the axes?

enter image description here

$\endgroup$
2
  • $\begingroup$ Would you be interested in a Frame based solution? $\endgroup$
    – Syed
    Mar 29, 2022 at 20:37
  • $\begingroup$ Any solution is welcome, but if it is possible, i would like to keep it as simple as it can be $\endgroup$
    – U.Grammy
    Mar 29, 2022 at 20:48

1 Answer 1

5
$\begingroup$

A plot that looks like the one in the picture posted in OP:

Plot[{1, 3, 5}, {x, 0, 35}, ImageSize -> Medium, Filling -> Axis,
  PlotRange -> {All, {0, 6}}, ScalingFunctions -> {None, "Reverse"}, 
  AxesLabel ->  {"T[°C]", z[mm]}] 

enter image description here

1. If it's not essential to have axes labels positioned at the ends, simplest approach is using Frame and Charting`ScaledTicks[{Identity, Identity}] to create horizontal axis ticks:

Plot[{1, 3, 5}, {x, 0, 35}, 
 Filling -> Axis, PlotRange -> {All, {0, 6}}, 
 ScalingFunctions -> {None, "Reverse"}, 
 FrameLabel -> {{z[mm], None}, {None, T[Row[{Degree , "C"}]]}}, 
 Frame -> {{True, False}, {False, True}}, 
 FrameTicks -> {{Automatic, None}, 
   {Automatic, Charting`ScaledTicks[{Identity, Identity}]}}]

enter image description here

Use Charting`ScaledTicks[{Identity, Identity}][0, 35, {8, 6}] to get

enter image description here

2. Alternative approach with more detailed control over positioning and styling of ticks and labels is to use AxisObject:

Create a version without the horizontal axis:

plot = Plot[{1, 3, 5}, {x, 0, 35}, ImageSize -> Medium, 
  Filling -> Axis, Axes -> {False, True}, PlotRange -> {All, {0, 6}}, 
  ScalingFunctions -> {None, "Reverse"}, AxesLabel ->  {None, z[mm]}, 
  Ticks -> {None, Automatic}]

enter image description here

and use AxisObject to construct an axis with desired features:

xaxis = Graphics @ AxisObject[Line[{{0, 0}, {35, 0}}], {0, 35}, 
    AxisLabel -> "  T[°C]", 
    TickPositions -> {{Range[5, 35, 5]}, {Range[35]}}, 
    AxisStyle -> Black, 
    TicksStyle -> {Black, Thickness -> Absolute[0.5]}, 
    TickLabelPositioning -> "Tip", 
    TickLengths -> {.15, .07}]

enter image description here

Combine plot and xaxis using Show:

Show[plot, xaxis] 

enter image description here

Remove the option TickLabelPositioning -> "Tip" and add the option TickDirection -> Down in definition of xaxis above to get

enter image description here

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.