<p dir="auto">Python 3.4<br>
Python 3 Matplotlib version is 1.4.2,<br>
Python 3 Numpy version is 1.8.2<br>
Reproduced with Python2.</p>
<p dir="auto">Installed on Raspbian Linux Jessie (RaspberryPi). Both installed with apt-get.</p>
<p dir="auto">I am creating a graph from a csv file that has the following format</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="08:21:05,41.0
08:22:05,41.0
08:23:05,41.0"><pre class="notranslate"><code class="notranslate">08:21:05,41.0
08:22:05,41.0
08:23:05,41.0
</code></pre></div>
<p dir="auto">The first column is the time (of course) and the second column is a centimetre measurement.</p>
<p dir="auto">I am updating an application I wrote to measure sump pit waterlevel activity to Python3 which requires converting<br>
the date from bytes to str as it was throwing an error.  Accepted bytes fine under Python2.</p>
<p dir="auto">The bytesdate2str function was courtesy github user cimarronm in another thread.</p>
<p dir="auto">The graph gets created with the following code;</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import time
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib import rcParams
rcParams.update({'figure.autolayout': True})

def bytesdate2str(fmt, encoding='utf-8'):
    '''Convert strpdate2num from bytes to string as required in Python3.

    This is a workaround as described in the following tread;
    https://github.com/matplotlib/matplotlib/issues/4126/

    Credit to github user cimarronm for this workaround.
    '''

    strconverter = mdates.strpdate2num(fmt)

    def bytesconverter(b):
        s = b.decode(encoding)
        return strconverter(s)
    return bytesconverter

def graph(csv_file, filename, bytes2str):
    '''Create a line graph from a two column csv file.'''

    unit = 'metric'
    date, value = np.loadtxt(csv_file, delimiter=',', unpack=True,
                             converters={0: bytes2str}
                             )
    fig = plt.figure(figsize=(10, 3.5))
    fig.add_subplot(111, axisbg='white', frameon=False)
    rcParams.update({'font.size': 9})
    plt.plot_date(x=date, y=value, ls='solid', linewidth=2, color='#FB921D',
                  fmt=':'
                  )
    title = &quot;Sump Pit Water Level {}&quot;.format(time.strftime('%Y-%m-%d %H:%M'))
    title_set = plt.title(title)
    title_set.set_y(1.09)
    plt.subplots_adjust(top=0.86)

    if unit == 'imperial':
        plt.ylabel('inches')
    if unit == 'metric':
        plt.ylabel('centimeters')

    plt.xlabel('Time of Day')
    plt.xticks(rotation=30)
    plt.grid(True, color='#ECE5DE', linestyle='solid')
    plt.tick_params(axis='x', bottom='off', top='off')
    plt.tick_params(axis='y', left='off', right='off')
    plt.savefig(filename, dpi=72)


csv_file = &quot;file.csv&quot;
filename = &quot;today.png&quot;

bytes2str = bytesdate2str('%H:%M:%S')
graph(csv_file, filename, bytes2str)
"><pre class="notranslate"><code class="notranslate">import time
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib import rcParams
rcParams.update({'figure.autolayout': True})

def bytesdate2str(fmt, encoding='utf-8'):
    '''Convert strpdate2num from bytes to string as required in Python3.

    This is a workaround as described in the following tread;
    https://github.com/matplotlib/matplotlib/issues/4126/

    Credit to github user cimarronm for this workaround.
    '''

    strconverter = mdates.strpdate2num(fmt)

    def bytesconverter(b):
        s = b.decode(encoding)
        return strconverter(s)
    return bytesconverter

def graph(csv_file, filename, bytes2str):
    '''Create a line graph from a two column csv file.'''

    unit = 'metric'
    date, value = np.loadtxt(csv_file, delimiter=',', unpack=True,
                             converters={0: bytes2str}
                             )
    fig = plt.figure(figsize=(10, 3.5))
    fig.add_subplot(111, axisbg='white', frameon=False)
    rcParams.update({'font.size': 9})
    plt.plot_date(x=date, y=value, ls='solid', linewidth=2, color='#FB921D',
                  fmt=':'
                  )
    title = "Sump Pit Water Level {}".format(time.strftime('%Y-%m-%d %H:%M'))
    title_set = plt.title(title)
    title_set.set_y(1.09)
    plt.subplots_adjust(top=0.86)

    if unit == 'imperial':
        plt.ylabel('inches')
    if unit == 'metric':
        plt.ylabel('centimeters')

    plt.xlabel('Time of Day')
    plt.xticks(rotation=30)
    plt.grid(True, color='#ECE5DE', linestyle='solid')
    plt.tick_params(axis='x', bottom='off', top='off')
    plt.tick_params(axis='y', left='off', right='off')
    plt.savefig(filename, dpi=72)


csv_file = "file.csv"
filename = "today.png"

bytes2str = bytesdate2str('%H:%M:%S')
graph(csv_file, filename, bytes2str)

</code></pre></div>
<p dir="auto">Using matplotlib for Python 3 I had to convert the date from bytes to str which is what the function bytesdate2str does.</p>
<p dir="auto">However the time on the x axis now appends .%f to the end.  I have been able to find some documentation on the matplotlib site around date formatting<br>
but I am having trouble figuring out how to remove that .%f</p>
<p dir="auto">Here is what the xticks looked like before without converting to str in python2.<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/8fff4044d19d174b082e8e7310d454eaa2b18b0a763e22bd80bb862205a92531/68747470733a2f2f7777772e6c696e75786e6f7274682e6f72672f72617370692d73756d702f696d616765732f72617370692d63686172742e706e67"><img src="https://camo.githubusercontent.com/8fff4044d19d174b082e8e7310d454eaa2b18b0a763e22bd80bb862205a92531/68747470733a2f2f7777772e6c696e75786e6f7274682e6f72672f72617370692d73756d702f696d616765732f72617370692d63686172742e706e67" alt="Good xticks image" data-canonical-src="https://www.linuxnorth.org/raspi-sump/images/raspi-chart.png" style="max-width: 100%;"></a></p>
<p dir="auto">Here is what the xticks looks like after converting from bytes to str (under both Python2 and 3)<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/1b8a05069ade2a8f5e245bd0d3639a7de6185c6772cf00907c05513f8b931635/68747470733a2f2f7777772e6c696e75786e6f7274682e6f72672f72617370692d73756d702f696d616765732f6261642e706e67"><img src="https://camo.githubusercontent.com/1b8a05069ade2a8f5e245bd0d3639a7de6185c6772cf00907c05513f8b931635/68747470733a2f2f7777772e6c696e75786e6f7274682e6f72672f72617370692d73756d702f696d616765732f6261642e706e67" alt="Bad xticks image" data-canonical-src="https://www.linuxnorth.org/raspi-sump/images/bad.png" style="max-width: 100%;"></a></p>
<p dir="auto">How do I remove %f from the end of the time? This is the only thing I have used matplotlib for and am a novice when it comes<br>
to the package.  Appreciate any insight you can provide.</p>
<p dir="auto">When plotting with a timestamp-based axis with datetimes of years <code class="notranslate">&lt;= 1900</code>, upon zooming into sub-second scales, the default axis label date formatter shows "%f" instead of microseconds.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [52]: import time, datetime, matplotlib.dates as mdates

In [53]: dt = mdates.date2num(datetime.datetime(1900, 1, 1, 10, 0))

In [54]: mdates.DateFormatter(&quot;%H:%M:%S.%f&quot;)(dt)
Out[54]: u'10:00:00.%f'

In [55]: time.strftime(&quot;%H:%M:%S.%f&quot;, (2000,) + mdates.num2date(dt).timetuple()[1:])
Out[55]: '10:00:00.%f'"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">52</span>]: <span class="pl-s1">import</span> <span class="pl-s1">time</span>, <span class="pl-s1">datetime</span>, <span class="pl-s1">matplotlib</span>.<span class="pl-s1">dates</span> <span class="pl-k">as</span> <span class="pl-s1">mdates</span>

<span class="pl-v">In</span> [<span class="pl-c1">53</span>]: <span class="pl-s1">dt</span> <span class="pl-c1">=</span> <span class="pl-s1">mdates</span>.<span class="pl-en">date2num</span>(<span class="pl-s1">datetime</span>.<span class="pl-en">datetime</span>(<span class="pl-c1">1900</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">10</span>, <span class="pl-c1">0</span>))

<span class="pl-v">In</span> [<span class="pl-c1">54</span>]: <span class="pl-s1">mdates</span>.<span class="pl-v">DateFormatter</span>(<span class="pl-s">"%H:%M:%S.%f"</span>)(<span class="pl-s1">dt</span>)
<span class="pl-v">Out</span>[<span class="pl-c1">54</span>]: <span class="pl-s">u'10:00:00.%f'</span>

<span class="pl-v">In</span> [<span class="pl-c1">55</span>]: <span class="pl-s1">time</span>.<span class="pl-en">strftime</span>(<span class="pl-s">"%H:%M:%S.%f"</span>, (<span class="pl-c1">2000</span>,) <span class="pl-c1">+</span> <span class="pl-s1">mdates</span>.<span class="pl-en">num2date</span>(<span class="pl-s1">dt</span>).<span class="pl-en">timetuple</span>()[<span class="pl-c1">1</span>:])
<span class="pl-v">Out</span>[<span class="pl-c1">55</span>]: <span class="pl-s">'10:00:00.%f'</span></pre></div>
<p dir="auto">This is since <code class="notranslate">timetuple</code> doesn't carry microsecond data. Minor in nature (was using a sentinel date of 1900 without realizing matplotlib would handle it specially) but I figured I would point it out.</p>