How to use scientific notation in a graph in Mathematica?

In summary, the conversation discusses the use of scientific notation in Mathematica for axes with small or large numbers. The code provided by the speaker allows for easy implementation of this feature, with options to choose which axis to display scientific notation on. The speaker also suggests editing the code to change the defaults.
  • #1
hanson
319
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
  • #2
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").
 
  • #3


I understand the importance of accurately representing data on a graph. When dealing with extremely large or small numbers, using scientific notation can make the data easier to read and understand. In Mathematica, there are a few ways to incorporate scientific notation into a graph.

One way is to use the "ExponentialForm" option when defining the axes. For example, if you have a plot with x and y axes ranging from 0 to 1000, you can use the following code to display the numbers in scientific notation:

Plot[x, {x, 0, 1000}, AxesLabel -> {Style["x", 16], Style["y", 16]}, AxesStyle -> Directive[FontSize -> 14, ExponentialForm -> True]]

This will display the numbers on the axes in the form of 1x10^3, 2x10^3, etc.

Another option is to use the "ScientificForm" function within the tick labels. For example, if you have a plot with the x axis ranging from 0 to 0.00001, you can use the following code to display the numbers in scientific notation:

Plot[x, {x, 0, 0.00001}, AxesLabel -> {Style["x", 16], Style["y", 16]}, Ticks -> {Automatic, Table[{ScientificForm, i}, {i, 0, 0.00001, 0.000001}]}]

This will display the numbers on the x axis as 1x10^-5, 2x10^-5, etc.

I hope this helps in incorporating scientific notation into your graphs in Mathematica. Don't get discouraged, as there are always solutions to any problem in science and technology. Good luck!
 

1. What is scientific notation and why is it used in graphs?

Scientific notation is a way of writing numbers that are very large or very small in a more compact and convenient form. It is often used in graphs to represent numbers that have a wide range of values, as it allows for easier comparison and interpretation of data.

2. How do I input numbers in scientific notation in Mathematica?

You can input numbers in scientific notation in Mathematica using the `*^` notation. For example, to input 1.5 x 10^4, you would type `1.5*^4` into Mathematica.

3. Can I change the format of numbers in scientific notation in a Mathematica graph?

Yes, you can change the format of numbers in scientific notation by using the `NumberFormat` function. This allows you to specify the number of decimal places, exponent alignment, and other formatting options.

4. How can I add units to numbers in scientific notation in a Mathematica graph?

To add units to numbers in scientific notation, you can use the `Unitize` function. This allows you to specify the unit you want to add, and it will automatically convert the number to scientific notation with the unit included.

5. Is it possible to adjust the axis labels in a Mathematica graph to display numbers in scientific notation?

Yes, you can use the `NumberFormat` function to adjust the axis labels in a Mathematica graph to display numbers in scientific notation. This can be especially useful when working with large or small numbers on a graph.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
257
  • MATLAB, Maple, Mathematica, LaTeX
Replies
23
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
985
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Back
Top