Best option for time series with Python matplotlib

(Last Updated On: January 12, 2016)

Best option for time series with Python matplotlib

There are 3 coding samples below which demo auto scaling for dates in Python’s MatPlotLib. Best one appears to be the last one.

Sourced links are listed as well

Join my FREE newsletter to learn how I use these coding samples for automated trading in Python

#http://stackoverflow.com/questions/29461608/matplotlib-fixing-x-axis-scale-and-autoscale-y-axis

# import numpy as np
# import matplotlib.pyplot as plt
#
# x, y = np.arange(0,101,1) ,300 - 0.1*np.arange(0,101,1)
# mask = (x >= 50) & (x <= 100)
#
# fig, ax = plt.subplots()
# ax.scatter(x[mask], y[mask])
#
# plt.show()

#http://stackoverflow.com/questions/32972371/how-to-show-date-and-time-on-x-axis-in-matplotlib
# import matplotlib.pyplot as plt
# import pandas as pd
# import matplotlib.dates as mdates
#
# times = pd.date_range('2015-10-06', periods=500, freq='10min')
#
# fig, ax = plt.subplots(1)
# fig.autofmt_xdate()
# plt.plot(times, range(times.size))
#
# xfmt = mdates.DateFormatter('%d-%m-%y %H:%M')
# ax.xaxis.set_major_formatter(xfmt)
#
# plt.show()

#this one works best and easiest it seems
#http://blog.mafr.de/2012/03/11/time-series-data-with-matplotlib/
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

days, impressions = np.loadtxt("page-impressions.csv", unpack=True,
        converters={ 0: mdates.strpdate2num('%Y-%m-%d')})

plt.plot_date(x=days, y=impressions, fmt="r-")
plt.title("Pageessions on example.com")
plt.ylabel("Page impressions")
plt.grid(True)
plt.show()
NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!
This entry was posted in Quant Development and tagged , , on by .

About caustic

Hi i there My name is Bryan Downing. I am part of a company called QuantLabs.Net This is specifically a company with a high profile blog about technology, trading, financial, investment, quant, etc. It posts things on how to do job interviews with large companies like Morgan Stanley, Bloomberg, Citibank, and IBM. It also posts different unique tips and tricks on Java, C++, or C programming. It posts about different techniques in learning about Matlab and building models or strategies. There is a lot here if you are into venturing into the financial world like quant or technical analysis. It also discusses the future generation of trading and programming Specialties: C++, Java, C#, Matlab, quant, models, strategies, technical analysis, linux, windows P.S. I have been known to be the worst typist. Do not be offended by it as I like to bang stuff out and put priorty of what I do over typing. Maybe one day I can get a full time copy editor to help out. Do note I prefer videos as they are much easier to produce so check out my many video at youtube.com/quantlabs