3
$\begingroup$

Absolute newbie question:

 Plot[2x-1,{x,-4,4},GridLines->{Range[-4,4],Range[-8,8]}]

Mathematica graphics

works about as expected, except that

  • (a) I would like the tick marks to be at integers only,
  • (b) I would like to control the ordinates so that the y scale is the same as for x.

By default, x goes in steps of .5 with labels at -4,-2, 2 and 4; y goes in steps of 1 with labels at -10, -5, and 5.

  • (c) I would like more of the tick marks to be labelled.

The result should look like something from an elementary algebra student handout. Hopefully, the grid and labels will stay the same even if the intercept and slope change.

Apologies for not inserting a picture in the question. It seems to involve more than snip, copy and paste.

Suggestions for improving my code will be appreciated.

$\endgroup$
  • $\begingroup$ Look up Ticks in the help system and study the examples. They show how to make the Ticks be almost anything you want. You might want to keep in mind that trying to make your output look like a textbook or published math paper is probably going to take several times as much time and effort to get it almost right as it took to get the mathematics exactly right. $\endgroup$ – Bill Nov 10 '14 at 7:09
  • $\begingroup$ Look up Ticks (or FrameTicks if you're using frames). Furthermore AspectRatio. These functions are all on a help document page of their own as well as on thePlot help page. $\endgroup$ – Sjoerd C. de Vries Nov 10 '14 at 7:10
  • $\begingroup$ Hi, welcome to Mathematica.SE, Thanks for taking the tour. Once you gain enough reputation by making good questions you will be able to vote up and down both questions and answers. Your question has been answered, and there are things to do after that. its good practice to wait a few hours for other answers before up-voting and accepting the best one for you. $\endgroup$ – rhermans Nov 10 '14 at 11:34
  • $\begingroup$ For simple image upload check this questions and answer $\endgroup$ – rhermans Nov 10 '14 at 11:47
4
$\begingroup$

This covers (a) and (b)

ticks[min_, max_] := Table[{i, Style[i, 14, Blue], {.04, 0}}, 
   {i, Ceiling[min], Floor[max]}]

Plot[2 x - 1, {x, -4, 4},
 GridLines -> {Range[-4, 4], Range[-8, 8]},
 GridLinesStyle -> LightGray,
 AspectRatio -> Automatic,
 Ticks -> ticks,
 PlotStyle -> Red]

Mathematica graphics

I am confused about (c)

(c) I would like more of the tick marks to be labeled

Because before you said

(a) I would like the tick marks to be at integers only,

I do not know how to put these 2 seemingly conflicting specifications on the same plot. If you have screen shot it will help.

$\endgroup$
2
$\begingroup$

If your aim in (c) is to add smaller unlabeled ticks, just add third argument, e.g.

Plot[2 x - 1, {x, -4, 4}, GridLines -> {Range[-4, 4], Range[-8, 8]},
 PlotStyle -> Red, GridLinesStyle -> LightBlue, 
 Ticks -> Table[
   Join[Table[{j, Style[j, Blue], {0, 0.04}}, {j, Range[-7, 7]}], 
    Table[{j, "", {0, 0.02}}, {j, -6.5, 6.5, 1}]], {2}], 
 AspectRatio -> Automatic, Background -> Lighter[LightOrange, 0.9]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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