[Matplotlib-users] Less tedious way to change the x-axis scale intervals with time series data?

2015-03-13 Thread pybokeh
Hello,
I'm trying to learn if there is a better or less tedious way of changing the
x-axis time scale interval size when plotting time series data using
MATPLOTLIB.

To account for all the different x-axis intervals that I may end up using, I
usually do the following imports:
from matplotlib.dates import YearLocator, MonthLocator, WeekdayLocator,
DateFormatter, DayLocator
from matplotlib.dates import MO, TU, WE, TH, FR, SA, SU

Then I specify specific intervals by doing the following:
year   = YearLocator()
month  = MonthLocator(bymonth=range(1,13),  bymonthday=1, interval=1)
week   = WeekdayLocator(byweekday=MO)  # Every MOnday
day= DayLocator(bymonthday=range(1,32), interval=1)

Then apply any of the above formats by doing:
axes.xaxis.set_major_locator(year)
axes.xaxis.set_major_locator(month)

I find all that above too tedious since I may then decide to change the
intervals to something different to experiment.

With R's ggplot2 or Yhat's ggplot, it is very simple and intuitive to change
the x-axis scale interval.  You just need to specify the breaks and
minor_breaks interval like so:
scale_x_datetime(labels=date_format("%Y-%m"), breaks="3 months",
minor_breaks="1 month")

I've quit using MATPLOTLIB for plotting time series data because of this. 
However, I thought perhaps there is a better way that I am not aware of.

If there is a better way, please educate me!  Thanks!



--
View this message in context: 
http://matplotlib.1069221.n5.nabble.com/Less-tedious-way-to-change-the-x-axis-scale-intervals-with-time-series-data-tp45175.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

--
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] linear regression with dates as x axis

2012-06-13 Thread pybokeh
Check out linregress from scipy.stats module.  Not sure if it will handle
dates.  Sample script below:

from scipy.stats import pearsonr from scipy.stats import linregress from
matplotlib import pyplot as plt import numpy as np

sat = np.array([595,520,715,405,680,490,565]) gpa =
np.array([3.4,3.2,3.9,2.3,3.9,2.5,3.5])

fig1 = plt.figure(1) ax = plt.subplot(1,1,1)

pearson = pearsonr(sat, gpa)

plt.scatter(sat,gpa, label="data")

# Get linear regression parameters slope, intercept, r_value, p_value,
std_err = linregress(sat, gpa)

# Format the chart plt.xlabel("SAT Scores") plt.ylabel("GPA")
plt.title("Scatter Plot with Linear Regression Fit\nY=a*X + b\na=%0.4f,
b=%0.4f" % (slope, intercept)) plt.grid()

# Create linear regression x values x_lr = sat

# Create linear regression y values: Y = slope*X + intercept y_lr = slope *
x_lr + intercept

print "Pearson correlation coefficient: ", pearson[0] print "Fit x-values:
", str(x_lr) print "Fit y-values: ", str(y_lr) print "Fit slope: ",slope
print "Fit intercept: ", intercept plt.plot(x_lr, y_lr, label="fit")
plt.legend()

plt.show()

Regards,
Daniel
On Jun 13, 2012 12:32 PM, "Chris Withers"  wrote:

> Hi all,
>
> I have some time series of disk usage that I'd like to do a linear
> regression on an plot on a nice graph with Mb used on the y-axis and
> date on the x axis.
>
> I tried to use pylab.polyfit(dates, usage) where:
>
> dates = [datetime(x, y, z), datetime(a, b, c), ...]
> usage = [12123234, 2234235235, ...]
>
> ...but polyfit doesn't like the dates.
>
> How should I do this?
>
> Any example of a nice plot and linear regression using matplotlib?
>
> cheers,
>
> Chris
>
> --
> Simplistix - Content Management, Batch Processing & Python Consulting
> - http://www.simplistix.co.uk
>
>
> --
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] linear regression with dates as x axis

2012-06-13 Thread pybokeh
Sorry looks like my smartphone's copy/paste removed carriage return in
certain places in the script :-(
On Jun 13, 2012 12:32 PM, "Chris Withers"  wrote:

> Hi all,
>
> I have some time series of disk usage that I'd like to do a linear
> regression on an plot on a nice graph with Mb used on the y-axis and
> date on the x axis.
>
> I tried to use pylab.polyfit(dates, usage) where:
>
> dates = [datetime(x, y, z), datetime(a, b, c), ...]
> usage = [12123234, 2234235235, ...]
>
> ...but polyfit doesn't like the dates.
>
> How should I do this?
>
> Any example of a nice plot and linear regression using matplotlib?
>
> cheers,
>
> Chris
>
> --
> Simplistix - Content Management, Batch Processing & Python Consulting
> - http://www.simplistix.co.uk
>
>
> --
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Scatter legend woes.

2012-06-14 Thread pybokeh
Are you trying to make 9 scatter plots?  In your for loop, if you are
trying to make a set of x values and a set of y values, then I think this
is wrong.  Since you didn't provide import statements I don't know which
rand() function you are using.  Assuming it is scipy.rand(), you will only
have one x value and one y value, not much of scatter chart with just one
point :-)

Otherwise, Mike's suggestion is valid.

Regards,
Daniel
On Jun 13, 2012 3:35 PM, "Steven Boada"  wrote:

> Whoops, I forgot to change the subject. Sorry list.
>
> List,
>
> I'm making a scatter plot using a for loop. Here's a simple example..
>
> for i in range(10):
> x=rand()
> y=rand()
> scatter(x,y,label='point')
>
> legend()
> show()
>
>
> When you do this, you get a legend entry for every single point. In this
> case, I get 9 entries in my legend.
>
> Is there a way to only get a single entry? I have looked into creating
> the legends by hand, but I'm not having much luck. Googling, only turned
> up a single example of someone else with the same problem.
>
> Help me list, you're my only hope.
>
> Steven
>
> On 06/13/2012 01:33 PM, Eric Firing wrote:
> > On 06/13/2012 07:31 AM, jonasr wrote:
> >> Hi,
> >>
> >> im actually trying to make a countour plot Z=f(X,Y) from two variables
> X,Y .
> >> My Problem is that i have to use a logarithmic scale for the Z values.
> >> If i plot the data with the logarithmic scale it gets pretty ugly,
> because i
> >> have a lot of values which are zero,
> >> which means on the log scale the value goes to -inf.
> >> Here is an example what i mean
> >>
> >> http://www.imagebanana.com/view/qh1khpxp/example.png
> >>
> >> I acutally have no idea how to make the plot look better,
> >> maybe somebody has an idea ?
> > Use np.ma.masked_less to mask out values below some threshold before
> > taking the log.
> >
> > e.g.,
> >
> > import matplotlib.pyplot as plt
> > import numpy as np
> > x = np.arange(0, 1, 0.01)
> > y = np.arange(0, 8, 0.05)
> > X, Y = np.meshgrid(x, y)
> > Z = 10 ** (-5 + 11 * X * np.sin(Y))
> > Z = np.ma.masked_less(Z, 1e-4)
> > Zlog = np.ma.log10(Z)
> > CS = plt.contourf(X, Y, Zlog, levels=np.arange(-3, 5.01, 1.0),
> > extend='both')
> > plt.colorbar()
> >
> >
> >
> > Eric
> >
> >> thank you
> >
> >
> --
> > Live Security Virtual Conference
> > Exclusive live event will cover all the ways today's security and
> > threat landscape has changed and how IT managers can respond. Discussions
> > will include endpoint security, mobile security and the latest in malware
> > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> > ___
> > Matplotlib-users mailing list
> > Matplotlib-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
>
> --
> Steven Boada
> Dept. Physics and Astronomy
> Texas A&M University
> bo...@physics.tamu.edu
>
>
>
> --
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users