Skip to main content
deleted 3 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k

This is the obvious solution, but it requires a lot of fussing with the details. I hope that you can use my code as a starting point. I am explicitly using years as the basic unit, so the code I give only works well if the data spans several years.

aapl = FinancialData["AAPL", {2000}];

(* extract start and end years  *)
{startYear, endYear} = aapl[[{1, -1}, 1, 1]]

(* these are tick mark and grid line locations *)
marks = Range[startYear, endYear];

(* these are label locations (all on JunJul 151); 
   I only show every second year for lack of space, 
   change it to fit your needs *)
labels = Table[{{year, 67, 151}, year, 0}, {year, startYear, endYear, 2}];

DateListPlot[aapl, Joined -> True, 
 GridLines -> {List /@ marks, Automatic},
 FrameTicks -> {
   Join[labels, {{#, 1, 1}, Null} & /@ marks],
   Automatic,
   {{#, 1, 1}, Null} & /@ marks,
   Automatic}]

Mathematica graphicsMathematica graphics

You can consider rotated labels for better space usage:

labels = Table[{{year, 67, 151}, Rotate[year, 90 Degree], 0}, 
            {year, startYear, endYear}];

Mathematica graphicsMathematica graphics

This is the obvious solution, but it requires a lot of fussing with the details. I hope that you can use my code as a starting point. I am explicitly using years as the basic unit, so the code I give only works well if the data spans several years.

aapl = FinancialData["AAPL", {2000}];

(* extract start and end years  *)
{startYear, endYear} = aapl[[{1, -1}, 1, 1]]

(* these are tick mark and grid line locations *)
marks = Range[startYear, endYear];

(* these are label locations (all on Jun 15); 
   I only show every second year for lack of space, 
   change it to fit your needs *)
labels = Table[{{year, 6, 15}, year, 0}, {year, startYear, endYear, 2}];

DateListPlot[aapl, Joined -> True, 
 GridLines -> {List /@ marks, Automatic},
 FrameTicks -> {
   Join[labels, {{#, 1, 1}, Null} & /@ marks],
   Automatic,
   {{#, 1, 1}, Null} & /@ marks,
   Automatic}]

Mathematica graphics

You can consider rotated labels for better space usage:

labels = Table[{{year, 6, 15}, Rotate[year, 90 Degree], 0}, 
            {year, startYear, endYear}];

Mathematica graphics

This is the obvious solution, but it requires a lot of fussing with the details. I hope that you can use my code as a starting point. I am explicitly using years as the basic unit, so the code I give only works well if the data spans several years.

aapl = FinancialData["AAPL", {2000}];

(* extract start and end years  *)
{startYear, endYear} = aapl[[{1, -1}, 1, 1]]

(* these are tick mark and grid line locations *)
marks = Range[startYear, endYear];

(* these are label locations (all on Jul 1); 
   I only show every second year for lack of space, 
   change it to fit your needs *)
labels = Table[{{year, 7, 1}, year, 0}, {year, startYear, endYear, 2}];

DateListPlot[aapl, Joined -> True, 
 GridLines -> {List /@ marks, Automatic},
 FrameTicks -> {
   Join[labels, {{#, 1, 1}, Null} & /@ marks],
   Automatic,
   {{#, 1, 1}, Null} & /@ marks,
   Automatic}]

Mathematica graphics

You can consider rotated labels for better space usage:

labels = Table[{{year, 7, 1}, Rotate[year, 90 Degree], 0}, 
            {year, startYear, endYear}];

Mathematica graphics

added 5 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k

This is the obvious solution, but it requires a lot of fussing with the details. I hope that you can use my code as a starting point. I am explicitly using years as the basic unit, so the code I give only works well if the data spans several years.

aapl = FinancialData["AAPL", {2000}];

(* extract start and end years  *)
{startYear, endYear} = aapl[[{1, -1}, 1, 1]]

(* these are tick mark and grid line locations *)
marks = Range[startYear, endYear];

(* these are label locations (all on Jun 15); 
   I only show every second year for lack of space, 
   change it to fit your needs *)
labels = Table[{{year, 6, 15}, year, 0}, {year, startYear, endYear, 2}];

DateListPlot[aapl, Joined -> True, 
 GridLines -> {List /@ marks, NoneAutomatic},
 FrameTicks -> {
   Join[labels, {{#, 1, 1}, Null} & /@ marks],
   Automatic,
   {{#, 1, 1}, Null} & /@ marks,
   Automatic}]

Mathematica graphicsMathematica graphics

You can consider rotated labels for better space usage:

labels = Table[{{year, 6, 15}, Rotate[year, 90 Degree], 0}, 
            {year, startYear, endYear}];

Mathematica graphicsMathematica graphics

This is the obvious solution, but it requires a lot of fussing with the details. I hope that you can use my code as a starting point. I am explicitly using years as the basic unit, so the code I give only works well if the data spans several years.

aapl = FinancialData["AAPL", {2000}];

(* extract start and end years  *)
{startYear, endYear} = aapl[[{1, -1}, 1, 1]]

(* these are tick mark and grid line locations *)
marks = Range[startYear, endYear];

(* these are label locations (all on Jun 15); 
   I only show every second year for lack of space, 
   change it to fit your needs *)
labels = Table[{{year, 6, 15}, year, 0}, {year, startYear, endYear, 2}];

DateListPlot[aapl, Joined -> True, 
 GridLines -> {List /@ marks, None},
 FrameTicks -> {
   Join[labels, {{#, 1, 1}, Null} & /@ marks],
   Automatic,
   {{#, 1, 1}, Null} & /@ marks,
   Automatic}]

Mathematica graphics

You can consider rotated labels for better space usage:

labels = Table[{{year, 6, 15}, Rotate[year, 90 Degree], 0}, 
            {year, startYear, endYear}];

Mathematica graphics

This is the obvious solution, but it requires a lot of fussing with the details. I hope that you can use my code as a starting point. I am explicitly using years as the basic unit, so the code I give only works well if the data spans several years.

aapl = FinancialData["AAPL", {2000}];

(* extract start and end years  *)
{startYear, endYear} = aapl[[{1, -1}, 1, 1]]

(* these are tick mark and grid line locations *)
marks = Range[startYear, endYear];

(* these are label locations (all on Jun 15); 
   I only show every second year for lack of space, 
   change it to fit your needs *)
labels = Table[{{year, 6, 15}, year, 0}, {year, startYear, endYear, 2}];

DateListPlot[aapl, Joined -> True, 
 GridLines -> {List /@ marks, Automatic},
 FrameTicks -> {
   Join[labels, {{#, 1, 1}, Null} & /@ marks],
   Automatic,
   {{#, 1, 1}, Null} & /@ marks,
   Automatic}]

Mathematica graphics

You can consider rotated labels for better space usage:

labels = Table[{{year, 6, 15}, Rotate[year, 90 Degree], 0}, 
            {year, startYear, endYear}];

Mathematica graphics

Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k

This is the obvious solution, but it requires a lot of fussing with the details. I hope that you can use my code as a starting point. I am explicitly using years as the basic unit, so the code I give only works well if the data spans several years.

aapl = FinancialData["AAPL", {2000}];

(* extract start and end years  *)
{startYear, endYear} = aapl[[{1, -1}, 1, 1]]

(* these are tick mark and grid line locations *)
marks = Range[startYear, endYear];

(* these are label locations (all on Jun 15); 
   I only show every second year for lack of space, 
   change it to fit your needs *)
labels = Table[{{year, 6, 15}, year, 0}, {year, startYear, endYear, 2}];

DateListPlot[aapl, Joined -> True, 
 GridLines -> {List /@ marks, None},
 FrameTicks -> {
   Join[labels, {{#, 1, 1}, Null} & /@ marks],
   Automatic,
   {{#, 1, 1}, Null} & /@ marks,
   Automatic}]

Mathematica graphics

You can consider rotated labels for better space usage:

labels = Table[{{year, 6, 15}, Rotate[year, 90 Degree], 0}, 
            {year, startYear, endYear}];

Mathematica graphics