Setting the ticks on an axis

Hello,

I was trying to change the tick values that show up on the y-axis. I
wanted a more finer range than the default. So I added:

        ax.set_yticks(range(ax.get_ylim()[0], ax.get_ylim()[1], 400))

to my plot. And before this line, I have

        ax.set_ylim(bottom=0, top=6000)

I get the results I want, but I get the following warning:

:91: DeprecationWarning: integer argument expected, got float
  ax.set_yticks(range(ax.get_ylim()[0], ax.get_ylim()[1], 400))

Is there a better way of doing this, other than explicitly typing the
lower and upper limits in ax.set_yticks() function.

Thank you.

Good evening,

Hello,

I was trying to change the tick values that show up on the y-axis. I
wanted a more finer range than the default. So I added:

ax.set_yticks(range(ax.get_ylim()[0], ax.get_ylim()[1], 400))

to my plot. And before this line, I have

ax.set_ylim(bottom=0, top=6000)

I get the results I want, but I get the following warning:

:91: DeprecationWarning: integer argument expected, got float
ax.set_yticks(range(ax.get_ylim()[0], ax.get_ylim()[1], 400))

To avoid having the warning, you can explicitly provide ints :

ax.set_yticks(range(int(ax.get_ylim()[0]), int(ax.get_ylim()[1]), 400))

I don’t know any easier method of setting the ticks… Let’s wait for the user community input !

Cheers,

Thomas

2011/2/19 Thomas Lecocq <thlecocq@...1954...>:

To avoid having the warning, you can explicitly provide ints :

ax.set_yticks(range(int(ax.get_ylim()[0]), int(ax.get_ylim()[1]), 400))

I don't know any easier method of setting the ticks... Let's wait for the
user community input !

If you don't want your floats converted to ints then use numpy arrange
or linespace.

Goyo

Thomas and Goyo,

Thanks for the answers. I am fine with them being coverted to ints. In
fact, my ax.set_ylim(bottom=0, top=6000) contains ints and I don't
understand why they are converted to floats. I was thinking that there
is perhaps another (more correct) way to set tick values. I will
either use Thomas' approach or Goyo's.

Thanks again.

···

On Sat, Feb 19, 2011 at 4:52 PM, Goyo <goyodiaz@...287...> wrote:

2011/2/19 Thomas Lecocq <thlecocq@...1954...>:

To avoid having the warning, you can explicitly provide ints :

ax.set_yticks(range(int(ax.get_ylim()[0]), int(ax.get_ylim()[1]), 400))

I don't know any easier method of setting the ticks... Let's wait for the
user community input !

If you don't want your floats converted to ints then use numpy arrange
or linespace.

Goyo

2011/2/20 Curiouslearn <curiouslearn@...287...>:

Thomas and Goyo,

Thanks for the answers. I am fine with them being coverted to ints. In
fact, my ax.set_ylim(bottom=0, top=6000) contains ints and I don't
understand why they are converted to floats. I was thinking that there
is perhaps another (more correct) way to set tick values.

You can use locators, but set_yticks is good enough for simple cases.
http://matplotlib.sourceforge.net/api/ticker_api.html