2
$\begingroup$

(I have MMA 10.0.2.0 running on a MacBook Pro with OS X 10.12.6.)

Before posting this question I looked at a number of interesting and helpful related posts: Is FrameTicks broken in 10.1.0?, How to express ticks in scientific form?, About the number format in ticks, How can I manipulate the number of decimal places in the frame ticks?, and Changing FrameTicks of ListPlot. I learned several things I did not know, for example that the FrameTicks specification changed from {bottom, left} to {{left, right},{bottom, top}} with MMA 7, but that the old spec was accepted until MMA 10. I also ran across, and installed, the CustomTicks.m package, which I did not know existed. My problem seems to be different, however, since it involves DateListPlot, which takes data in a somewhat different form.

Let's start with the data:

data = { {{2013}, 7.18956914`*^6}, {{2014}, 9.56534036`*^6}, 
         {{2015}, 1.048495813`*^7}, {{2016}, 8.38576746`*^6}, 
         {{2017}, 7.62914337`*^6} }

The extra curly brackets around the year lets DateListPlot interpret it as an SQL date spec (even if the month, day, hr, min, and sec are missing).

The first attempt was before I knew of the different formatting:

DateListPlot[data,
    PlotStyle -> {Thickness[0.007], RGBColor[1, 0, 0]},
    GridLines -> Automatic,
    FrameTicks -> {Automatic, 
                   NumberForm[#, {8, 1}, ExponentFunction -> (Null &), 
                   DigitBlock -> 3] &},
    LabelStyle -> Directive[FontSize -> 13, Bold],
    PlotRange -> {{{2012}, {2018}}, {0, 15000000}},
    FrameLabel -> {None, Style["Volume", Bold]},
    PlotLegends -> SwatchLegend[{"blabla"},
                   LegendMarkers -> 
                   Graphics[{EdgeForm[Black], Opacity[1], Rectangle[]}]]
     ]

enter image description here

As you can see, the year came out great, but there is nothing on the y-axis. The second attempt used CustomTicks and the correct formatting for the FrameTicks spec:

DateListPlot[data,
    PlotStyle -> {Thickness[0.007], RGBColor[1, 0, 0]},
    GridLines -> Automatic,
    FrameTicks -> {{LinTicks, None}, {LinTicks, None}},
    LabelStyle -> Directive[FontSize -> 13, Bold],
    PlotRange -> {{{2012}, {2018}}, {0, 15000000}},
    FrameLabel -> {None, Style["Volume", Bold]},
    PlotLegends -> SwatchLegend[{"blabla"},
                   LegendMarkers -> 
                   Graphics[{EdgeForm[Black], Opacity[1], Rectangle[]}]]
   ]

enter image description here

This time the volume labels on the left are roughly OK (I would rather have commas separating thousands) but the dates are messed up. This is most probably because CustomTicks was developed for physics problems rather than financial problems, and in fact dates are not mentioned at all in its manual. The last attempt is not to use CustomTicks and to try something a bit fancier with a function specification:

DateListPlot[data,
    PlotStyle -> {Thickness[0.007], RGBColor[1, 0, 0]},
    GridLines -> Automatic,
    FrameTicks -> {{NumberForm[#, {8, 1}, ExponentFunction -> (Null &), 
                    DigitBlock -> 3] &, None}, {Automatic, None}},
    LabelStyle -> Directive[FontSize -> 13, Bold],
    PlotRange -> {{{2012}, {2018}}, {0, 15000000}},
    FrameLabel -> {None, Style["Volume", Bold]},
    PlotLegends -> SwatchLegend[{"blabla"},
                   LegendMarkers -> 
                   Graphics[{EdgeForm[Black], Opacity[1], Rectangle[]}]]
   ]

enter image description here

Still no luck. I even got several error messages about NumberForm. One is telling me that DigitBlock should be a positive integer, which it is!! If I change {8, 1} to {Infinity, 0}, which I would prefer, I get a different error message telling me that it, too, should be a positive integer or a pair of positive integers.

The original objective was to get rid of the exponential notation for the volume and show it in decimal notation with no digits after the decimal point. The closest I got was with CustomTicks, but the year got messed up.

In conclusion, I am lost and would be very grateful for some enlightenment on how to deal with a problem that originally seemed rather trivial to solve.

$\endgroup$
  • $\begingroup$ do you get the desired result if you use the options GridLines -> {Automatic, FindDivisions[{0, 15000000}, 6] } and FrameTicks -> {{FindDivisions[{0, 15000000}, 6], Automatic}, Automatic}? $\endgroup$ – kglr Dec 25 '17 at 13:42
  • $\begingroup$ Yes! Thank you @kglr, that's great! I see I needed an additional hash. $\endgroup$ – pdini Dec 25 '17 at 13:42
  • $\begingroup$ My answer just above is to the NumberForm solution, which is now the answer I accepted. I also tried FindDivisions and it worked even applying it only to FrameTicks. Thanks again. $\endgroup$ – pdini Dec 25 '17 at 16:23
2
$\begingroup$
DateListPlot[data, PlotStyle -> {Thickness[0.007], RGBColor[1, 0, 0]},
 GridLines -> {Automatic, FindDivisions[{0, 15000000}, 6] }, 
 FrameTicks -> {{FindDivisions[{0, 15000000}, 6], Automatic},  Automatic}, 
 LabelStyle -> Directive[FontSize -> 13, Bold], 
 PlotRange -> {{{2012}, {2018}}, {0, 15000000}}, ImageSize->500]

enter image description here

To have , as digit block separator, replace FindDivisions[{0, 15000000}, 6] with

{#, NumberForm[#, 8, ExponentFunction -> (Null &), DigitBlock -> 3]} & /@ 
  FindDivisions[{0, 15000000}, 6]

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.