3
$\begingroup$

Consider a simple plot with textual x ticks.

ListPlot[
 {{1, 2, 3}, {2, 4, 6}},
 Ticks -> {Table[{i, (Characters@"ab")[[i]]}, {i, 2}], Automatic},
 AxesLabel -> {"character", "val"},
 PlotLegends -> {"r", "w"}
 ]

enter image description here

How to place the x-axis label below the x axis?

Note that several solutions to this popular question on SE suggest

  • using Frame with FrameLabel. I tried this but it hides the ticks
  • Using Labeled. It kind of works though the look and feel of the y axis label from AxesLabel and x axis label from Labeled differ.

I am open to using Labeled alone as long as the y axis label looks similar to x-axis' and is properly oriented.

$\endgroup$

2 Answers 2

2
$\begingroup$

You do not show how you tried to use Frame so it is unclear why you say it caused the label to hide the ticks. Perhaps you did not change Ticks to FrameTicks

ListPlot[{{1, 2, 3}, {2, 4, 6}},
 Frame -> {{True, False}, {True, False}},
 FrameTicks ->
  {Table[{i, (Characters@"abc")[[i]]}, {i, 3}], Automatic},
 FrameLabel -> (Style[#, 12, Bold] & /@ {"character", "val"}),
 PlotLegends -> {"r", "w"},
 PlotMarkers -> {Automatic, 8}]

enter image description here

$\endgroup$
1
  • $\begingroup$ thnx...yeah i was using normal Ticks $\endgroup$
    – lineage
    Sep 9, 2020 at 13:06
1
$\begingroup$

Here's a solution that uses Labeled for both labels:

Labeled[
 ListPlot[
  {{1, 2, 3}, {2, 4, 6}},
  Ticks -> {Table[{i, (Characters@"ab")[[i]]}, {i, 2}], Automatic},
  PlotLegends -> {"r", "w"}
  ],
 {"character", "val"},
 {Bottom, {Top, Left}},
 LabelStyle -> {"Graphics", "GraphicsAxes", "GraphicsLabel"}
 ]

enter image description here

Using Labeled for both has of course the advantage that both labels look exactly the same, no matter how you style them. But since we can get the exact style used by the default labels, we can also specify the y-label using AxesLabel:

Labeled[
 ListPlot[
  {{1, 2, 3}, {2, 4, 6}},
  Ticks -> {Table[{i, (Characters@"ab")[[i]]}, {i, 2}], Automatic},
  PlotLegends -> {"r", "w"},
  AxesLabel -> {"character", "val"}
  ],
 "character",
 Bottom,
 LabelStyle -> {"Graphics", "GraphicsAxes", "GraphicsLabel"}
 ]
$\endgroup$
2
  • $\begingroup$ thnx for the quick solve...simple&works.... can you please explain the meaning of LabelStyle -> {"Graphics", "GraphicsAxes", "GraphicsLabel"} $\endgroup$
    – lineage
    Sep 9, 2020 at 12:58
  • $\begingroup$ Those refer to named styles as defined in the stylesheet (Format>Edit stylesheet>Click on Default.nb>Click on Core.nb>Search for "Graphics"). The fact that those are used is mentioned in the documentation for Graphics in the second to last point in the details section. To find the exact combination of styles, I simply tried different combinations and modified the styles a bit too see what affects what. $\endgroup$
    – Lukas Lang
    Sep 9, 2020 at 13:06

Your Answer

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

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