axvspan with dates on x-axis

I want to place a colored vertical range on my plot and came across the following example:

http://stackoverflow.com/questions/8270981/in-a-matplotlib-plot-can-i-highlight-specific-x-value-ranges/8271438#8271438

It shows what I am trying to do using axvspan.

However, I was not able to reproduce the second plot with dates.

Errors like ‘invalid syntax’ for color=‘red’ and others prevented me from reproducing the plot.

The demo from Matplotlib gallery worked fine for me. My plot also has dates on the x-axis.

I am attaching code and data file. Hope someone can point me in the right direction.

L Fleischfresser

NotasFaltasdoisgraficos.py (2 KB)

NotasFaltasMec22012.csv (970 Bytes)

Looks like your very close.

I needed to change the months to short English form, change the line

   ax3.grid('True') to ax3.grid(True)

and add the line

   ax3.axvspan(*mdates.datestr2num(['05/18/2012', '06/30/2012']),
facecolor='g', alpha=0.5)

To get the box on the lower plot.

Hope that helps,

···

On 23 July 2012 20:42, Luciano Fleischfresser <l_fle@...9...> wrote:

I want to place a colored vertical range on my plot and came across the
following example:

http://stackoverflow.com/questions/8270981/in-a-matplotlib-plot-can-i-highlight-specific-x-value-ranges/8271438#8271438

It shows what I am trying to do using axvspan.
However, I was not able to reproduce the second plot with dates.
Errors like 'invalid syntax' for color='red' and others prevented me from
reproducing the plot.
The demo from Matplotlib gallery worked fine for me. My plot also has dates
on the x-axis.

I am attaching code and data file. Hope someone can point me in the right
direction.

L Fleischfresser

------------------------------------------------------------------------------
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

Still not working. The output looks like this:

File “NotasFaltasdoisgraficos.py”, line 58

ax3.axvspan(*mdates.datestr2num([‘05/18/2012’, ‘06/30/2012’]), facecolor=‘g’, alpha=0.5)

****^

SyntaxError: invalid syntax

When you say “…change the months to
short English form” you mean in the data file?

That is, Abr -> Apr, Mai -> May??? …still did not work.

···

From: Phil Elson <pelson.pub@…287…>
To: Luciano Fleischfresser <lfle@…3463…>
Cc: “Matplotlib-users@…1735…sourceforge.net” Matplotlib-users@lists.sourceforge.net
Sent: Monday, July 23, 2012 5:45 PM
Subject: Re: [Matplotlib-users] axvspan with dates on x-axis

Looks like your very close.

I needed to change the months to short English form, change the line

ax3.grid(‘True’) to ax3.grid(True)

and add the line

ax3.axvspan(*mdates.datestr2num([‘05/18/2012’, ‘06/30/2012’]),
facecolor=‘g’, alpha=0.5)

To get the box on the lower plot.

Hope that helps,

On 23 July 2012 20:42, Luciano Fleischfresser <l_fle@…9…> wrote:

I want to place a colored vertical range on my plot and came across the
following example:

http://stackoverflow.com/questions/8270981/in-a-matplotlib-plot-can-i-highlight-specific-x-value-ranges/8271438#8271438

It shows what I am trying to do using axvspan.
However, I was not able to reproduce the second plot with dates.
Errors like ‘invalid syntax’ for color=‘red’ and others prevented
me from
reproducing the plot.
The demo from Matplotlib gallery worked fine for me. My plot also has dates
on the x-axis.

I am attaching code and data file. Hope someone can point me in the right
direction.

L Fleischfresser


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@…1220…sts.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@…1220…sts.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Luciano got in touch offline and my suggestions worked for a certain
version of Python.

Luciano, were you trying it in python3? If not, what version of Python
was it that wasn't working for you?

Thanks,

···

On 24 July 2012 18:26, Luciano Fleischfresser <l_fle@...9...> wrote:

Still not working. The output looks like this:

File "NotasFaltasdoisgraficos.py", line 58
   ax3.axvspan(*mdates.datestr2num(['05/18/2012', '06/30/2012']),
facecolor='g', alpha=0.5)

^
SyntaxError: invalid syntax

When you say "...change the months to short English form" you mean in the
data file?
That is, Abr -> Apr, Mai -> May??? ...still did not work.

________________________________
From: Phil Elson <pelson.pub@...287...>
To: Luciano Fleischfresser <lfle@...3463...>
Cc: "Matplotlib-users@lists.sourceforge.net"
<Matplotlib-users@lists.sourceforge.net>
Sent: Monday, July 23, 2012 5:45 PM
Subject: Re: [Matplotlib-users] axvspan with dates on x-axis

Looks like your very close.

I needed to change the months to short English form, change the line

  ax3.grid('True') to ax3.grid(True)

and add the line

  ax3.axvspan(*mdates.datestr2num(['05/18/2012', '06/30/2012']),
facecolor='g', alpha=0.5)

To get the box on the lower plot.

Hope that helps,

On 23 July 2012 20:42, Luciano Fleischfresser <l_fle@...9...> wrote:

I want to place a colored vertical range on my plot and came across the
following example:

http://stackoverflow.com/questions/8270981/in-a-matplotlib-plot-can-i-highlight-specific-x-value-ranges/8271438#8271438

It shows what I am trying to do using axvspan.
However, I was not able to reproduce the second plot with dates.
Errors like 'invalid syntax' for color='red' and others prevented me from
reproducing the plot.
The demo from Matplotlib gallery worked fine for me. My plot also has
dates
on the x-axis.

I am attaching code and data file. Hope someone can point me in the right
direction.

L Fleischfresser

------------------------------------------------------------------------------
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

It is Python 2.5.2 (r252.60911, Jan 24 2010, 14:53:14)

[GCC 4.3.2] on linux2.

I believe the Matplotlib version there is outdated or the locale is an issue.

Thanks for the help!

···

From: Phil Elson <pelson.pub@…287…>
To: Luciano Fleischfresser <lfle@…3463…>
Cc: ""Matplotlib-users@lists.sourceforge.net""
Matplotlib-users@lists.sourceforge.net
Sent: Thursday, July 26, 2012 5:02 AM
Subject: Re: [Matplotlib-users] axvspan with dates on x-axis

Luciano got in touch offline and my suggestions worked for a certain
version of Python.

Luciano, were you trying it in python3? If not, what version of Python
was it that wasn’t working for you?

Thanks,

On 24 July 2012 18:26, Luciano Fleischfresser <l_fle@…9…> wrote:

Still not working. The output looks like this:

File “NotasFaltasdoisgraficos.py”, line 58
ax3.axvspan(*mdates.datestr2num([‘05/18/2012’, ‘06/30/2012’]),
facecolor=‘g’, alpha=0.5)

^
SyntaxError: invalid syntax

When you say “…change the months to short English form” you mean in the
data file?
That is, Abr -> Apr, Mai -> May??? …still did not work.


From: Phil Elson <pelson.pub@…287…>
To: Luciano Fleischfresser <lfle@…3463…>
Cc: "Matplotlib-users@lists.sourceforge.net"
Matplotlib-users@lists.sourceforge.net
Sent: Monday, July 23, 2012 5:45 PM
Subject: Re: [Matplotlib-users] axvspan with dates on x-axis

Looks like your very close.

I needed to change the months to short English form, change the line

ax3.grid(‘True’) to ax3.grid(True)

and add the line

ax3.axvspan(*mdates.datestr2num([‘05/18/2012’, ‘06/30/2012’]),
facecolor=‘g’, alpha=0.5)

To get the box on the lower plot.

Hope that helps,

On 23 July 2012 20:42, Luciano Fleischfresser <l_fle@…9…> wrote:

I want to place a colored vertical range on my plot and came across the
following example:

http://stackoverflow.com/questions/8270981/in-a-matplotlib-plot-can-i-highlight-specific-x-value-ranges/8271438#8271438

It shows what I am trying to do using axvspan.
However, I was not able to reproduce the second plot with dates.
Errors like ‘invalid syntax’ for color=‘red’ and others prevented me from
reproducing the plot.
The demo from
Matplotlib gallery worked fine for me. My plot also has

dates
on the x-axis.

I am attaching code and data file. Hope someone can point me in the right
direction.

L Fleischfresser


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@…1220…sts.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@…504…et
https://lists.sourceforge.net/lists/listinfo/matplotlib-users