2
$\begingroup$

Following is the mathematica command I am using to obtain a contour plot(attached). I see that the length of minor and major ticks are very small. What is a good command to increase the length of both ticks?.

Table[ContourPlot[
  f[\[ScriptCapitalD], {x, y}], {x, 55, 80}, {y, 15, 25}, 
  PlotRange -> Full,  
  PlotLegends -> 
   BarLegend[Automatic, LabelStyle -> {FontSize -> 32, Black}], 
  ContourStyle -> Thickness[0.004],  ColorFunction -> GrayLevel, 
  Axes -> True, 
  FrameLabel -> {Style["x (m)", 32], Style["y (m)", 32]},  
  Contours -> 10, LabelStyle -> Black, FrameStyle -> Thickness[.005], 
  AxesStyle -> Black, ContourStyle -> Black, ContourShading -> None, 
  FrameTicksStyle -> Directive[FontSize -> 12], 
  BaseStyle -> {FontSize -> 21}, 
  AspectRatio -> 1/2.5 ], {f, {PDF, CDF}}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Did you look help for FrameTicks. There is an example under Generalization and Extensions fticks[min_, max_] := Table[If[EvenQ[i], {i, i, {.1, 0}, Red}, {i, i, {.05, 0}, Blue}], {i, Ceiling[min], Floor[max], 1}] $\endgroup$
    – ercegovac
    Sep 29, 2017 at 22:01
  • $\begingroup$ It appears that help does not cover this. You can look help for Ticks. It is essentially the same function. $\endgroup$
    – ercegovac
    Sep 29, 2017 at 22:04

2 Answers 2

4
$\begingroup$

Though not clearly written in MMA help, FrameTicks accept function in a similar way as Ticks do. Hence the following code can be tweaked to do the job.

ClearAll[fticks]
fticks[min_, max_]:=Module[{division = Subdivide[min, max, 10]}, Table[If[EvenQ[i], {(*pos*)division[[i]], (*lbl*)i,(*size*) {.1, 0},(*col*)Red}, {(*pos*)division[[i]],(*lbl*)i,(*size*){.05, 0},(*col*) Blue}], {i, Range@Length@division}]]
Plot[Sin[t], {t, 0, 2 Pi}, Frame -> True, FrameTicks -> fticks]

which gives

enter image description here

You can tweak the code to get what you want. Read help documentation for Ticks to see more use cases.

$\endgroup$
3
$\begingroup$

Update 2: As noted by @ercegovac in a comment, using @Carl's fix in this answer, the approach in my original answer below also works in Version 11:

Show[cp, FrameTicks -> fticks]

enter image description here

Update: Using a modification of the function tickF from this answer to create a custom ticks function:

ClearAll[tickF];
tickF[s_ : 1][div1_, div2_ : -1] := (If[div2 == -1, 
    Thread[{#, #, s {.02, 0}}, List, 2] &@ FindDivisions[{#1, #2}, div1], 
    Join @@ MapAt[Join @@ # &, {Thread[{#, #, s {.02, 0}}, List, 2] &@#[[1]], 
      Thread[{#, "", s {.01, 0}}, List, 2] & /@ #[[2]]} &@
       FindDivisions[{#1, #2}, {div1, div2}], {2}]]) &

Example:

ft = (tickF[3][8, 5][## & @@ #] & /@ PlotRange[cp]);
Show[cp, FrameTicks -> {{ft[[2]], ft[[2]]}, {ft[[1]], ft[[1]]}}]

enter image description here

Original answer:

The following approach works in version 9:

cp = ContourPlot[Evaluate[Re[Product[x + I y - (a + I b), {a, -2, 2}, {b, -2, 2}]]],
  {x, -3, 3}, {y, -3, 3}, ImageSize -> 400];

Get the FrameTicks using AbsoluteOptions and post-process to increase the tick lengths:

fticks = FrameTicks /. AbsoluteOptions[cp, FrameTicks]; 
fticks[[All, All, 3]] = 5 fticks[[All, All, 3]];

Use fticks as the option value for FrameTicks in Show:

cp2 = Show[cp, ImageSize -> 400, FrameTicks -> fticks];
Row[{cp, cp2}]

enter image description here

$\endgroup$
8
  • $\begingroup$ I was curious about your approach. However, it throws error when tried to executed on my machine. See this link. $\endgroup$
    – ercegovac
    Sep 29, 2017 at 22:22
  • $\begingroup$ @ercegovac, I cannot open the link. Please check if the updated version I just posted gives the same error. $\endgroup$
    – kglr
    Sep 29, 2017 at 22:56
  • $\begingroup$ It throws error {Automatic,Automatic} is not a valid tick specification. Seams that graphics directive contains FrameTicks -> {{Automatic, Automatic}, {Automatic, Automatic}}. Possibly looking furhter into Theme for resolution. I have "11.2.0 for Microsoft Windows (64-bit) (September 11, 2017)" $\endgroup$
    – ercegovac
    Sep 29, 2017 at 23:03
  • $\begingroup$ @ercegovac, it looks like AbsoluteOptions doesn't work in version 11 (it does in version 9). I will post an alternative approach if/when I can think of one:) $\endgroup$
    – kglr
    Sep 29, 2017 at 23:15
  • $\begingroup$ It appears that, with introduction of Themes, the way MMA handles plotting changed. Now, default styles are found under PlotThemes. There is quite some discussion on that topic. I do not know who of the users is from Wolfram on this forum, but they should add in the help for FrameTicks that it can accept function in the same way as Ticks. Currently one has to go under Generalization and Extensions to see the usecase example. $\endgroup$
    – ercegovac
    Sep 29, 2017 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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