2
$\begingroup$

I would like to shorten this repetitious code. Personally, I would save the labels in a separate variable and then just refer to the variable, like for example "ChartLabels -> mylabels". This way the plot function itself doesn't look cluttered.

ChartLabels -> {Rotate[
   "2\[Times]\!\(\*SuperscriptBox[\(10\), \(4\)]\)", 45 Degree],
  Rotate[Style["4\[Times]\!\(\*SuperscriptBox[\(10\), \(4\)]\)", 12], 
   45 Degree],
  Rotate[Style["6\[Times]\!\(\*SuperscriptBox[\(10\), \(4\)]\)", 12], 
   45 Degree],
  Rotate[Style["8\[Times]\!\(\*SuperscriptBox[\(10\), \(4\)]\)", 12], 
   45 Degree],
  Rotate[Style["1\[Times]\!\(\*SuperscriptBox[\(10\), \(5\)]\)", 12], 
   45 Degree],
  Rotate[Style["1.2\[Times]\!\(\*SuperscriptBox[\(10\), \(5\)]\)", 
    12], 45 Degree],
  Rotate[Style["1.4\[Times]\!\(\*SuperscriptBox[\(10\), \(5\)]\)", 
    12], 45 Degree],
  Rotate[Style["1.6\[Times]\!\(\*SuperscriptBox[\(10\), \(5\)]\)", 
    12], 45 Degree],
  Rotate[Style["1.8\[Times]\!\(\*SuperscriptBox[\(10\), \(5\)]\)", 
    12], 45 Degree],
  Rotate[Style["2\[Times]\!\(\*SuperscriptBox[\(10\), \(5\)]\)", 12], 
   45 Degree]}
$\endgroup$
3
  • $\begingroup$ Welcome to Mma.SE! Your question needs more from your side. Here it's considered helpful and polite to show your own efforts and share your data and code attempts in a well formatted form, so we can quickly see the problem you are facing. Please help us to help you and edit your question accordingly. Also, please take the tour, it will help you understand the site. If you write an excellent question it will inspire great answers. $\endgroup$
    – rhermans
    Commented May 11, 2023 at 14:28
  • $\begingroup$ You could make things more compact with Iconize. Is that what you are after? What have you tried? $\endgroup$
    – rhermans
    Commented May 11, 2023 at 14:30
  • $\begingroup$ Personally, I would save the labels in a separate variable and then just refer to the variable, like for example "ChartLabels -> mylabels". This way the plot function itself doesn't look cluttered. $\endgroup$
    – banone
    Commented May 11, 2023 at 14:35

2 Answers 2

3
$\begingroup$

Another fast way would be the following

ChartLabels -> (Rotate[Style[ScientificForm[1. #  10^4], 12], 
 45 Degree] & /@ Range[2, 20,2])

enter image description here

$\endgroup$
2
$\begingroup$

One way could be:

Clear[f];
f[num_Integer] := 
 RowBox[{NumberForm[10 First@#, {3, 1}], "x", 
      SuperscriptBox[10, Last@# - 1]}] &@ 
   MantissaExponent[1.0 num, 10] // DisplayForm
ChartLabels -> (Rotate[#, 45 Degree] & /@ 
   f /@ Range[2 10^4, 2 10^5, 2 10^4])

enter image description here


EDIT

The advantage of using additional pieces of information provided by MantissaExponent is that another function f2 can be defined and used (with minor style changes). For example:

f2[num_Integer] := 
 RowBox[{Framed[#, Background -> Yellow] &@
       NumberForm[10 First@#, {3, 1}], "x", 
      SuperscriptBox[10, Style[Last@# - 1, Red]]}] &@ 
   MantissaExponent[1.0 num, 10] // DisplayForm

ChartLabels -> (Rotate[#, 45 Degree] & /@ 
   f2 /@ Range[2 10^4, 2 10^5, 2 10^4])

enter image description here

$\endgroup$

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.