0

I am using the snippet given here as the starting point for a script. I want to display a volume chart at the bottom of the first (i.e. main) chart. The volume subchart is basically plotted vertical bars.

Ideally, the date (i.e. X axis) labels will be underneath the volume subplot - i.e. the same date (X) axis is used for both the top (main) chart and the subplot. However, if it makes life easier (for anyone submitting a snippet), I can live with a volume subchart (with or without its own X axis date labels).

I find the matplotlib documentation and scattered tutorials very confusing. A link to an example where this kind of graphing is done (or a snippet posted here) will be very useful

Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
  • 1
    I understand what you want is basically [this](http://matplotlib.sourceforge.net/users/pyplot_tutorial.html#working-with-multiple-figures-and-axes) with a couple changes (mainly the common X axis labels), isn't it? – Ricardo Cárdenes Feb 12 '12 at 17:15
  • @RicardoCárdenes: Yes, your understanding is correct. The 'volume' chart will basically be vertical bars (looks like the chart below the image in the link you provided) – Homunculus Reticulli Feb 12 '12 at 19:28

1 Answers1

1

Modify the ax declaration of the subplot to

ax = fig.add_subplot(211)

and comment out the minor_formatter declaration of #ax.xaxis.set_minor_formatter(dayFormatter)

and append the following before the show() call

fig.subplots_adjust(hspace=0.5)
ay = fig.add_subplot(212)
ay.xaxis.set_major_locator(mondays)
ay.xaxis.set_minor_locator(alldays)
ay.xaxis.set_major_formatter(weekFormatter)
dates = [ x[0] for x in quotes]
volumes = [ x[-1] for x in quotes]
ay.bar(dates,volumes,0.35)

This gives a volume subchart with its own X axis date labels

Appleman1234
  • 15,946
  • 45
  • 67
  • This almost works, but I notices two 'quirks': 1). It **overwrites** the bottom part of the existing chart. 2). There are two inexplicable gaps in the volume chart - one at the begining of the volume chart and the other at the end of the volume chart, which seems to suggest that the X axis scaling is different, since the volume chart data starts later (and finishes earlier) than the chart in the top (main) chart – Homunculus Reticulli Feb 12 '12 at 19:31
  • Updated the snippet to use the same x data in both plots, which should remedy quirk 2. I can't reproduce quirk 1. as the `fig.subplots_adjust(hspace=0.5)` ensures that the vertical space between the two subplots is enough to avoid overwriting. – Appleman1234 Feb 12 '12 at 19:59