Re: [Matplotlib-users] How to Change Axis Tick Mark Labels
Ah, sorry, forgot to reply to all. Please see the solution I provided to Jon. -- Forwarded message -- Date: 22 July 2012 15:08 Subject: Re: [Matplotlib-users] How to Change Axis Tick Mark Labels Sounds like you want to use a FunctionFormatter rather than modifying the ticks themselves. There is an example here (http://stackoverflow.com/questions/8271564/matplotlib-comma-separated-number-format-for-axis). Essentially: import matplotlib.pyplot as plt import matplotlib.ticker as mticker def square_braces(tick_val, tick_pos): Put square braces around the given tick_val return '%s' % tick_val ax = plt.axes() plt(range(10)) ax.yaxis.set_major_formatter(mticker.FuncFormatter(func)) plt.show() HTH, -- 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] Possible to change MPL color scheme?
On Mon, Jul 23, 2012 at 05:50:41AM +0200, klo uo wrote: Thanks for your reply Ben, On Sun, Jul 22, 2012 at 4:39 PM, Benjamin Root wrote: As for the assertion that HTML colors aren't used, that is incorrect. The named colors follow the HTML list. Here is our list: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/colors.py#L62 and here is the html list: http://html-color-codes.info/color-names/ sure that's correct, I just meant about default defined colors with abbrev color names, like 'y' (#BFBF00) in not 'yellow' (#00) etc. Are you saying the following two examples ax.plot(x, y, 'yellow') ax.plot(x, y, 'y') produce different coloured lines? Or are you saying yellow should always be #00? -- 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 -- Damon McDougall http://damon-is-a-geek.com B2.39 Mathematics Institute University of Warwick Coventry West Midlands CV4 7AL United Kingdom -- 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] How to Change Axis Tick Mark Labels
On 23/07/2012 03:01, JonBL wrote: Using FuncFormatter with my conversion procedure has solved my problem. I did not use the Python datetime module to generate the tickmark labels as some of your examples suggested. Instead, my conversion procedure pulls the required formatted date string for an x-axis ticklabel date serial number from an Oracle database which is the source of my plotted data. This approach has also answered another question I had in mind - how do I get the x= co-ordinate displayed at the bottom of the figure, to report the formatted date rather than its serial number. I also had a response from Phil Elson who suggested using using FuncFormatter as well. Many thanks to both of you for your timely responses to my query. Regards, Jon Brilliant :) I was just about to ask how to do this!!! Benjamin Root-2 wrote: On Sat, Jul 21, 2012 at 10:27 PM, JonBL jc.bl...@bigpond.net.au wrote: I have a line plot where the x-axis values are numbers, with displayed tick mark values of 0, 100, 200 ... 500 - a total of 6 tick marks. These values represent the number of days since a certain date. I have a function which converts a number such as 100, to date string '23-Jun-11', which I want to display as the x-axis label instead of 100. Following the pypib example xaxis_props.py, and printing dir(label) for each label in the x-axis tick labels, I can see that a label object supports a number of methods that might assist in changing the text of tick mark labels. I was hoping to use the get_text() method to retrieve the label's text (eg, 100), transform this to a date string by my function, and then use the set_text() method to re-assign the displayed label. This approach does not work for me. The get_text() method returns a zero-length string (not None) for each label, and the set_text() method does not change the displayed tick mark values. But I can use the set_color() method to change the colour of displayed values as per example xaxis_props.py. Any suggestions on how to change the text of displayed x-axis tick marks? TIA, Jon Without example code, it would be difficult to determine what you are doing incorrectly. That being said, there is an easier solution. If you know the start date, do the following: from datetime import datetime, timedelta startdate = datetime.strptime(datestr, %d-%m-%y) # you need to look up the format character for named months. xdates = np.array([startdate + timedelta(days=i) for i in xrange(501)]) y = np.random.random(xdates.shape) plt.plot(xdates, y)# This should work, but plot_date() definitely will work. Matplotlib recognizes the python datetime object and should format it for you. You can even control the formatting. See the following examples: http://matplotlib.sourceforge.net/examples/pylab_examples/date_demo_convert.html?highlight=datetime%20codex http://matplotlib.sourceforge.net/examples/pylab_examples/date_demo2.html?highlight=datetime%20codex http://matplotlib.sourceforge.net/examples/api/date_demo.html?highlight=datetime%20codex http://matplotlib.sourceforge.net/examples/pylab_examples/date_demo1.html?highlight=datetime%20codex I hope this helps! Ben Root -- 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 -- Cheers. Mark Lawrence. -- 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
[Matplotlib-users] 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 Description: Binary data NotasFaltasMec22012.csv Description: Binary data -- 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] 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_...@yahoo.com 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