<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">When plotting the <a href="https://github.com/matplotlib/matplotlib/files/696920/bug.zip">attached</a> time vs. masked arrays using <code class="notranslate">plot_date</code>, <code class="notranslate">matplotlib</code> chooses a timespan of 4½ years despite the time axis covering less than 4 days (I had to make it a zip or github would not permit it as an attachment).  This happens because most of the data in <code class="notranslate">y</code> is masked; the data in the time-axis are not masked at all, so it should still be able to choose a sensible time range.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="plot_date(t, x)"><pre class="notranslate"><code class="notranslate">plot_date(t, x)
</code></pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/500246/21818304/2c712cbc-d75f-11e6-9d80-b242764beb26.png"><img src="https://cloud.githubusercontent.com/assets/500246/21818304/2c712cbc-d75f-11e6-9d80-b242764beb26.png" alt="actual outcome" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">The expected span of time axes is obtained with</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="plot_date(t.data, x.data)"><pre class="notranslate"><code class="notranslate">plot_date(t.data, x.data)
</code></pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/500246/21818347/5e1b1a52-d75f-11e6-8e62-357aa0f7e946.png"><img src="https://cloud.githubusercontent.com/assets/500246/21818347/5e1b1a52-d75f-11e6-8e62-357aa0f7e946.png" alt="expected outcome" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Matplotlib version</strong></p>
<p dir="auto">I'm using matplotlib 2.0.0rc2 installed through pip</p>
<p dir="auto">As explained in my original StackOverflow <a href="http://stackoverflow.com/q/35163031/4739755" rel="nofollow">question</a>, I've found some unexpected behavior when plotting single points in matplotlib.pyplot with Datetime objects. Plotting multiple points (&gt;1) gives the range of dates with some buffer on either side. Plotting a single point causes the range to span multiple years (2014 - 2018 using Feb 03, 2016).</p>
<p dir="auto">When using the AutoDateLocator(), the (assumed) issue isn't as noticeable since the generated ticks are fairly conservative, but using a WeekdayLocator() instead results in a dense mess of ticks. The application I'm using this for deals with time spans of <em>at most</em> a few months, so suddenly getting a range of multiple <em>years</em> is quite jarring.</p>
<p dir="auto">Below is some code that generates 6 matplotlib.pyplot plot images to demonstrate a few example cases and the output from running the script with the --verbose-debug flag</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt
import matplotlib.dates as md
from datetime import datetime

# Create figures
fig0 = plt.figure(0)
fig1 = plt.figure(1)
fig2 = plt.figure(2)
fig3 = plt.figure(3)
fig4 = plt.figure(4)
fig5 = plt.figure(5)
fig6 = plt.figure(6)
# Add some subplots
sub3 = fig3.add_subplot(111)
sub4 = fig4.add_subplot(111)
sub5 = fig5.add_subplot(111)
sub6 = fig6.add_subplot(111)

# Creating a regular plot directly with a single point
plt.figure(0)
plt.plot((2,), (3,), marker='o')
plt.title('Regular plot, single point')

# Doing the same, but with a subplot
sub3.plot((2,), (3,), marker='o')
sub3.set_title('Subplot, single point')

# Creating a regular plot using a Datetime object with multiple points
# Using the AutoDateLocator()
test_date_one = datetime.strptime('2016-02-03', '%Y-%m-%d')
test_date_two = datetime.strptime('2016-03-03', '%Y-%m-%d')

plt.figure(1)
plt.plot((test_date_one, test_date_two), (2, 3), marker='o')
fig1.autofmt_xdate()
plt.title('Regular plot, multiple Datetime points')

# Now with a single point
plt.figure(2)
plt.plot(test_date_one, 2, marker='o')
fig2.autofmt_xdate()
plt.title('Regular plot, single Datetime point')

# Doing the same, but with a subplot
# Multiple points
sub4.plot((test_date_one, test_date_two), (2, 3), marker='o')
fig4.autofmt_xdate()
sub4.set_title('Subplot, multiple Datetime points')

# Single point
sub5.plot(test_date_one, 2, marker='o')
fig5.autofmt_xdate()
sub5.set_title('Subplot, single Datetime point')

# Finally, single Datetime point with WeekdayLocator()
sub6.plot(test_date_two, 3, marker='o')
sub6.xaxis.set_major_locator(md.WeekdayLocator())
fig6.autofmt_xdate()
sub6.set_title('Subplot, single Datetime point, WeekdayLocator()')

plt.show()"><pre class="notranslate"><code class="notranslate">import matplotlib.pyplot as plt
import matplotlib.dates as md
from datetime import datetime

# Create figures
fig0 = plt.figure(0)
fig1 = plt.figure(1)
fig2 = plt.figure(2)
fig3 = plt.figure(3)
fig4 = plt.figure(4)
fig5 = plt.figure(5)
fig6 = plt.figure(6)
# Add some subplots
sub3 = fig3.add_subplot(111)
sub4 = fig4.add_subplot(111)
sub5 = fig5.add_subplot(111)
sub6 = fig6.add_subplot(111)

# Creating a regular plot directly with a single point
plt.figure(0)
plt.plot((2,), (3,), marker='o')
plt.title('Regular plot, single point')

# Doing the same, but with a subplot
sub3.plot((2,), (3,), marker='o')
sub3.set_title('Subplot, single point')

# Creating a regular plot using a Datetime object with multiple points
# Using the AutoDateLocator()
test_date_one = datetime.strptime('2016-02-03', '%Y-%m-%d')
test_date_two = datetime.strptime('2016-03-03', '%Y-%m-%d')

plt.figure(1)
plt.plot((test_date_one, test_date_two), (2, 3), marker='o')
fig1.autofmt_xdate()
plt.title('Regular plot, multiple Datetime points')

# Now with a single point
plt.figure(2)
plt.plot(test_date_one, 2, marker='o')
fig2.autofmt_xdate()
plt.title('Regular plot, single Datetime point')

# Doing the same, but with a subplot
# Multiple points
sub4.plot((test_date_one, test_date_two), (2, 3), marker='o')
fig4.autofmt_xdate()
sub4.set_title('Subplot, multiple Datetime points')

# Single point
sub5.plot(test_date_one, 2, marker='o')
fig5.autofmt_xdate()
sub5.set_title('Subplot, single Datetime point')

# Finally, single Datetime point with WeekdayLocator()
sub6.plot(test_date_two, 3, marker='o')
sub6.xaxis.set_major_locator(md.WeekdayLocator())
fig6.autofmt_xdate()
sub6.set_title('Subplot, single Datetime point, WeekdayLocator()')

plt.show()
</code></pre></div>
<p dir="auto"><strong>Debug Output</strong><br>
$HOME=C:\Users******<br>
matplotlib data path C:\Python27\lib\site-packages\matplotlib\mpl-data</p>
<hr>
<p dir="auto">You have the following UNSUPPORTED LaTeX preamble customizations:</p>
<p dir="auto">Please do not ask for support with these customizations active.</p>
<hr>
<p dir="auto">loaded rc file C:\Python27\lib\site-packages\matplotlib\mpl-data\matplotlibrc<br>
matplotlib version 1.5.1<br>
verbose.level debug<br>
interactive is False<br>
platform is win32<br>
loaded modules: &lt;dictionary-keyiterator object at 0x04E08810&gt;<br>
CACHEDIR=C:\Users*<em><strong>.matplotlib<br>
Using fontManager instance from C:\Users*</strong></em>.matplotlib\fontList.cache<br>
backend TkAgg version 8.5<br>
Could not load matplotlib icon: can't use "pyimage10" as iconphoto: not a photo image<br>
Could not load matplotlib icon: can't use "pyimage19" as iconphoto: not a photo image<br>
Could not load matplotlib icon: can't use "pyimage28" as iconphoto: not a photo image<br>
Could not load matplotlib icon: can't use "pyimage37" as iconphoto: not a photo image<br>
Could not load matplotlib icon: can't use "pyimage46" as iconphoto: not a photo image<br>
Could not load matplotlib icon: can't use "pyimage55" as iconphoto: not a photo image<br>
findfont: Matching :family=sans-serif:style=normal:variant=normal:weight=400:stretch=normal:size=medium to Bitstream Vera Sans (u'c:\python27\lib\site-packages\matplotlib\mpl-data\fonts\ttf\Vera.ttf') with score of 0.000000<br>
findfont: Matching :family=sans-serif:style=normal:variant=normal:weight=400:stretch=normal:size=large to Bitstream Vera Sans (u'c:\python27\lib\site-packages\matplotlib\mpl-data\fonts\ttf\Vera.ttf') with score of 0.000000</p>