KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm having trouble using multiple subplots with dates on the x-axis. I'm using the matplotlib example from here . I've modified it to include another subplot (the data being plotted is the same). This is what I'm getting as output: The ticks appear only on the second subplot. Why? How can I make them appear on both subplots? Here's my modified source. I've added code to include a new subplot in the if block halfway through the source. #!/usr/bin/env python """ Show how to make date plots in matplotlib using date tick locators and formatters. See major_minor_demo1.py for more information on controlling major and minor ticks All matplotlib date plotting is done by converting date instances into days since the 0001-01-01 UTC. The conversion, tick locating and formatting is done behind the scenes so this is most transparent to you. The dates module provides several converter functions date2num and num2date """ import datetime import numpy as np import matplotlib import matplotlib.pyplot as plt import matplotlib.dates as mdates import matplotlib.mlab as mlab import matplotlib.cbook as cbook years = mdates.YearLocator() # every year months = mdates.MonthLocator() # every month yearsFmt = mdates.DateFormatter('%Y') # load a numpy record array from yahoo csv data with fields date, # open, close, volume, adj_close from the mpl-data/example directory. # The record array stores python datetime.date as an object array in # the date column #datafile = cbook.get_sample_data('goog.npy') datafile = 'goog.npy' r = np.load(datafile).view(np.recarray) fig = plt.figure() ax = fig.add_subplot(211) ax.plot(r.date, r.adj_close) # format the ticks ax.xaxis.set_major_locator(years) ax.xaxis.set_major_formatter(yearsFmt) ax.xaxis.set_mino
Tags (comma-separated)
Save Edits
Cancel