On Oct 7, 2010, at 3:38 PM, Waléria Antunes David wrote:

> Hi,
> 
> I did like the links below, but seeing as it was my chart.
> 
> See
> 
> My code: http://pastebin.com/KcjHAPLN
> 
> On Thu, Oct 7, 2010 at 3:08 PM, John Hunter <jdh2...@gmail.com> wrote:
> On Thu, Oct 7, 2010 at 1:01 PM, Waléria Antunes David
> <waleriantu...@gmail.com> wrote:
> > I need to know how do these vertical lines on the graph. See the picture,
> > the lines circled.
> 
> We call these major and minor ticks.  The major ticks are the taller
> ones, the minor ticks are the smaller ones.  Their location is
> controlled by the major and minor Locator instances, and the text
> printed beside them is controlled by the major and minor formatter.
> 
> See
> 
>  
> http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo1.html
>  
> http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo2.html
> 
> and
> 
>  http://matplotlib.sourceforge.net/search.html?q=codex+set_minor_locator
> 
> To control the tick properties themselves, see the Tick section in
> 
>  http://matplotlib.sourceforge.net/users/artists.html
> 
> JDH
> 
> <graph.png>

As John mentioned, the major and minor ticks were the taller and shorter ticks, 
respectively. In your pasted example, you only change the minor ticks; by 
setting the majorLocator to same value as in the original example (i.e. 20), 
you only get the major tick at 0 because your data only goes to 1.5 (i.e. 20 is 
outside your plot range).

Also, the majorFormatter in the example is set to work with integers, but your 
major tick labels should be float values (since most of them are between 0 and 
1). Thus, the majorFormatter code is unnecessary (commented out below).

Finally, a pet peeve: when posting example code, please make the effort to 
generate data for the plot so that others can easily run the code (see 
attached).

-Tony

#---

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter

def gera_grafico(N=200, eps=1):

    x = np.abs(np.random.randn(N))
    y = 10*np.log((30*x + 1.)**(0.5)) + 34 + eps * np.random.randn(N)
    yerr = eps * np.random.randn(N)

    majorLocator   = MultipleLocator(0.2)
    # majorFormatter = FormatStrFormatter('%d')
    minorLocator   = MultipleLocator(0.02)
    
    fig, ax = plt.subplots()
    plt.errorbar(x, y, yerr, fmt='ob', label='date')

    plt.xlim(0.0, 1.5)
    #plt.xscale('log')
    #grid(True)

    ax.xaxis.set_major_locator(majorLocator)
    # ax.xaxis.set_major_formatter(majorFormatter)

    ax.xaxis.set_minor_locator(minorLocator)

    return fig

if __name__ == '__main__':
    gera_grafico()
    plt.show()


------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to