Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to emulate this plot using Mathematica.

enter image description here

Using the following command, I cannot get the grid points correct.

  Plot[{x, x^2, x^3}, {x, -4, 4}, Frame -> True, FrameTicks -> All, 
   FrameTicksStyle -> {{Black, Blue}, {Red, Green}}, 
   GridLines -> {Range[-4, 4], Range[-25, 25]}]

This results in:

enter image description here

Is there something that can be done to get it to look like the first plot (which was done using Microsoft Equation)?

share|improve this question
3  
You can use the third argument of Range to control the distance between gridlines and you can use GridLinesStyle to control their appearance. – C. E. Jan 8 at 7:56
    
For the internal ticks this may be of help – Ymareth Jan 8 at 8:42
up vote 8 down vote accepted

If all you need to do is make the gridlines look better, just change your plot command to have these options GridLines -> {Range[-4, 4, .5], Range[-32, 32, 4]},GridLinesStyle -> LightGray. But if you want to fully reproduce that plot, see below.

Something like this is not an exact reproduction

Plot[{x, x^2, x^3}, {x, -4, 4},
 PlotRange -> {-33, 33},
 Frame -> True,
 Ticks -> {LinTicks, LinTicks},
 FrameTicks -> All,
 FrameTicksStyle -> {{Black, Blue}, {Red, Green}},
 GridLines -> {Range[-4, 4, .5], Range[-32, 32, 4]},
 GridLinesStyle -> LightGray,
 ImageSize -> 600,
 FrameStyle -> ColorData[97][1],
 AxesStyle -> Directive[ColorData[97][1], Arrowheads[0.03]]]

enter image description here

But man, would be nice if we could have tick marks on the axes as well as on the frame. According to this post this is impossible without using Overlay (and I hate using Overlay). There is a neat solution using extraAxisPlot from this post

baseplot = Plot[{x, x^2, x^3}, {x, -4, 4},
   PlotRange -> {-33, 33},
   Frame -> True,
   FrameTicks -> All,
   FrameTicksStyle -> {{Black, Blue}, {Red, Green}},
   GridLines -> {Range[-4, 4, .5], Range[-32, 32, 4]},
   GridLinesStyle -> LightGray,
   ImageSize -> 600,
   FrameStyle -> ColorData[97][1],
   Axes -> False];

extraAxisPlot[baseplot, {{-3.8, -30}, {3.8, 30}}, {-3.8, -30},
 "AxisType" -> "Both",
 "AxisOptions" -> {AxesStyle -> 
    Directive[ColorData[97][1], Arrowheads[0.03]], 
   LabelStyle -> {FontOpacity -> 0}}]

enter image description here

Edit As Nasser says it is hard to put the tick labels inside the frame - you have to use Heike's solution, but then that Epilog will override the Epilog that shows the axes so I need to give another option to extraAxisPlot

baseplot = Plot[{x, x^2, x^3}, {x, -4.2, 4.2},
   PlotRange -> {-34, 34},
   Frame -> True,
   FrameTicks -> All,
   FrameTicksStyle -> (FontOpacity -> 0),
   GridLines -> {Range[-4, 4, .5], Range[-32, 32, 4]},
   GridLinesStyle -> LightGray,
   ImageSize -> 600,
   FrameStyle -> ColorData[97][1],
   Axes -> False];

Show[extraAxisPlot[baseplot, {{-3.8, -30}, {3.8, 30}}, {-3.8, -30},
  "AxisType" -> "Both",
  "AxisOptions" -> {AxesStyle -> 
     Directive[ColorData[97][1], Arrowheads[0.03]], 
    LabelStyle -> {FontOpacity -> 0}}, 
  "ExtraEpilog" -> {Table[
     Text[i, {i, -34}, {0, -1}, BaseStyle -> ColorData[97][1]], {i, 
      Range[-4, 4, 2]}],
    Table[
     Text[i, {i, 34}, {0, 1}, BaseStyle -> ColorData[97][1]], {i, 
      Range[-4, 4, 2]}],
    Table[
     Text[i, {-4.2, i}, {-.5, 0}, BaseStyle -> ColorData[97][1]], {i, 
      Range[-30, 30, 10]}],
    Table[
     Text[i, {4.2, i}, {.5, 0}, BaseStyle -> ColorData[97][1]], {i, 
      Range[-30, 30, 10]}]}]]

enter image description here

share|improve this answer

maybe this is a start. Putting the ticks inside is kind'a hard. (ps. the yellow background, is from Mathematica itself. I have to accept yellow color in place of pausing when opening any new notebook or window. So I took the yellow color. Mathematica graphic card bug on windows)

Mathematica graphics

glx = Table[
   If [Mod[i, 2] == 
     0, {i, {Blue, Thickness[0.005]}}, {i, {Thin, Blue}}], {i, -4, 4, .5}];
gly = Table[
   If [Mod[i, 16] == 
     0, {i, {Blue, Thickness[0.005]}}, {i, {Thin, Blue}}], {i, -32, 32, 4}];
Plot[{x, x^2, x^3}, {x, -4, 4},
 Frame -> True,
 FrameTicksStyle -> Blue,
 GridLines -> {glx, gly},
 PlotRange -> {{-4.5, 4.5}, {-36, 36}},
 ImageSize -> 500,
 Axes -> False,
 Epilog -> {
   {Thick, Arrowheads[Small], Arrow[{{-3, 0}, {3, 0}}]},
   {Thick, Arrowheads[Small], Arrow[{{0, -30}, {0, 30}}]},
   Text[Style[Style["y"], Italic], {-.1, 28}], 
   Text[Style["x", Italic], {3, -2}]
   },
 PlotStyle -> {FontFamily -> "Times"},
 FrameTicks -> {{Range[-32, 32, 16], Range[-32, 32, 16]}, {Range[-4, 4, 2], 
    Range[-4, 4, 2]}}
 ]
share|improve this answer
    
Could this be related to your yellow tint? link – AxelF Jan 8 at 12:36
    
@AxelF exactly. After making that "fix" in the question there, my Mathematica got inflicted with the dreaded Formatting Notebook Contents problem each time I open any new notebook or do anything. So I removed the graphic card update and went back to the yellow Mathematica, but now without having to suffer with Formatting Notebook Contents. 10.3.1 on windows 7, 64 bit. – Nasser Jan 8 at 19:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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