How to use scientific notation in a graph in Mathematica?

Click For Summary
SUMMARY

This discussion provides a solution for using scientific notation on graph axes in Mathematica, specifically for versions 6 and higher. The user shares a custom function, ScientificTicks, which allows for the display of scientific notation on either or both axes of a plot. The function takes a plot as its first argument and two optional boolean arguments to specify whether to apply scientific notation to the x-axis and y-axis. Examples demonstrate its application with the Plot function for the exponential function.

PREREQUISITES
  • Familiarity with Mathematica 6 or higher
  • Understanding of plotting functions in Mathematica
  • Basic knowledge of scientific notation
  • Ability to modify and execute code in Mathematica
NEXT STEPS
  • Explore advanced plotting techniques in Mathematica
  • Learn about customizing ticks and labels in Mathematica plots
  • Investigate the use of AbsoluteOptions for plot customization
  • Study the Show function for combining graphics in Mathematica
USEFUL FOR

Mathematica users, data visualizers, and anyone needing to enhance the readability of graphs with scientific notation on axes.

hanson
Messages
312
Reaction score
0
When the numbers on the axis are too small or too big, I would like to use scientific notation for that axes in mathematica...
Anyone know how to do it...
I have googles it and find no useful things. Kind of frustrated.
 
Physics news on Phys.org
Grabbed this little piece of code from the 'net somewhere and made it a bit more user-friendly. It works in Mathematica 6 and higher (if you are using a version < 6 you have to add some DisplayFunctions to hide the initial plot and only show it at the end)

Code:
ScientificTicks[plot_Graphics, xSci_: False, ySci_: True] := 
  Module[{t},
   Show[plot, 
    Ticks -> {(t = Ticks /. AbsoluteOptions[plot, Ticks])[[1]] /. 
       If[xSci, {x_, xlab_?NumericQ, r__} -> {x, ScientificForm[x], 
          r}, {}], 
      t[[2]] /. 
       If[ySci, {y_, ylab_?NumericQ, r__} -> {y, ScientificForm[y], 
          r}, {}]}]
   ];

The first argument is a plot and the next two arguments indicate whether you want scientific notation on the x- and y-axis, respectively. If you leave them out you will get scientific notation on the y-axis only.
Code:
(* Normal on x, Scientific on y *)
ScientificTicks[Plot[Exp[x], {x, 0, 100}], False, True]
ScientificTicks[Plot[Exp[x], {x, 0, 100}], False]
ScientificTicks[Plot[Exp[x], {x, 0, 100}]]
(* Scientific on x, Normal on y *)
ScientificTicks[Plot[Exp[x], {x, 0, 100}], True, False]
(* Scientific on both *)
ScientificTicks[Plot[Exp[x], {x, 0, 100}], True, True]
ScientificTicks[Plot[Exp[x], {x, 0, 100}], True]

You can edit the defaults in the first line (e.g. change "xSci_:False" to "xSci_:True").
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K