Hi all,
My name is Marianne, I am a beginner user of matplotlib.
I am using imshow in pyplot. I am desperate to get rid of
the ticks on both x and y axes (see attached picture). I
do not need the black box around the data either. Should
I use imshow in axes.Axes instead, to be able to call
set_ticks_position("none")?
Thank you for your help,
Marianne
Here is the code so far:
import numpy
from matplotlib import pyplot
q=numpy.loadtxt(‘field.txt’)
myfield = pyplot.imshow(q,aspect=1)
myfield.set_clim(vmin=0, vmax=0.6)
pyplot.colorbar()
pyplot.savefig(‘field_1.eps’)
field_1.pdf (404 KB)
Hello,
I am sending my email again, with no attachment this time.
Thanks for reading!
Marianne
···
On Thu, Nov 24, 2011 at 3:48 PM, Marianne C. <mariyanna.c@…287…> wrote:
Hi all,
My name is Marianne, I am a beginner user of matplotlib.
I am using imshow in pyplot. I am desperate to get rid of
the ticks on both x and y axes (see attached picture). I
do not need the black box around the data either. Should
I use imshow in axes.Axes instead, to be able to call
set_ticks_position("none")?
Thank you for your help,
Marianne
Here is my script so far:
import numpy
from matplotlib import pyplot
q=numpy.loadtxt(‘field.txt’)
myfield = pyplot.imshow(q,aspect=1)
myfield.set_clim(vmin=0, vmax=0.6)
pyplot.colorbar()
pyplot.savefig(‘field_1.eps’)
2011/11/24 Marianne C. <mariyanna.c@...287...>:
Hi all,
My name is Marianne, I am a beginner user of matplotlib.
I am using imshow in pyplot. I am desperate to get rid of
the ticks on both x and y axes (see attached picture). I
do not need the black box around the data either. Should
The cleanes solution, is to use the NullLocator. I'm not a user of
pylab Matlabish interface, but from what I know::
gca().xaxis.set_major_locator(matplotlib.ticker.NullLocator())
gca().yaxis.set_major_locator(matplotlib.ticker.NullLocator())
after importing matplotlib.ticker of course. Should work, but didn't try.
http://matplotlib.sourceforge.net/api/ticker_api.html
http://matplotlib.sourceforge.net/api/axis_api.html#matplotlib.axis.Axis.set_major_locator
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.gca
You are free to use the OO interface which yields the same.
Notice that upon clear() the locators are most probably lost.
gca() get the current Axes object. xaxis and yaxis are its Axis
attributes. The locator defines where to set ticks. If it's the
NoneLocator this is rather a stub to saying "don't place ticks ever".
But it's more clean than to force them directly to the empty list
because it'll survive at least limit changes. I don't know if the
manual method survives that. Otherwise it's also a matter of taste.
From the docs I do not see that you could hand over the locators
directly to the imshow call
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.imshow.
For the frame, if it really matters, you can set the ``edgecolor``
probably to 'none', literally with the quotes. There's a Figure
object created when you create the plot, you can get it via gcf().
Try to figure out how to set its egdecolor either on construction or
later. If you are stuck tell.
Make sure to "reply to all".
cu,
Friedrich
···
On Thu, Nov 24, 2011 at 3:48 PM, Marianne C. <mariyanna.c@...287...> wrote:
Hi Friedrich and everybody else,
Thank you for your reply.
I think I am not getting everything, but in my understanding,
the object which I create is not a Figure or an Axis, it is an
AxesImage. gca() or gcf() return errors indeed.
Therefore, I cannot use attributes which are specific to Figures
and Axes.
Would there be a reason for the class AxesImage to handle
very few attributes? Is this class not so popular? 
Best,
Marianne
···
On Thu, Nov 24, 2011 at 8:09 PM, Friedrich Romstedt <friedrichromstedt@…287…> wrote:
2011/11/24 Marianne C. <mariyanna.c@…287…>:
On Thu, Nov 24, 2011 at 3:48 PM, Marianne C. <mariyanna.c@…287…> wrote:
Hi all,
My name is Marianne, I am a beginner user of matplotlib.
I am using imshow in pyplot. I am desperate to get rid of
the ticks on both x and y axes (see attached picture). I
do not need the black box around the data either. Should
The cleanes solution, is to use the NullLocator. I’m not a user of
pylab Matlabish interface, but from what I know::
gca().xaxis.set_major_locator(matplotlib.ticker.NullLocator())
gca().yaxis.set_major_locator(matplotlib.ticker.NullLocator())
after importing matplotlib.ticker of course. Should work, but didn’t try.
http://matplotlib.sourceforge.net/api/ticker_api.html
http://matplotlib.sourceforge.net/api/axis_api.html#matplotlib.axis.Axis.set_major_locator
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.gca
You are free to use the OO interface which yields the same.
Notice that upon clear() the locators are most probably lost.
gca() get the current Axes object. xaxis and yaxis are its Axis
attributes. The locator defines where to set ticks. If it’s the
NoneLocator this is rather a stub to saying “don’t place ticks ever”.
But it’s more clean than to force them directly to the empty list
because it’ll survive at least limit changes. I don’t know if the
manual method survives that. Otherwise it’s also a matter of taste.
From the docs I do not see that you could hand over the locators
directly to the imshow call
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.imshow.
For the frame, if it really matters, you can set the edgecolor
probably to ‘none’, literally with the quotes. There’s a Figure
object created when you create the plot, you can get it via gcf().
Try to figure out how to set its egdecolor either on construction or
later. If you are stuck tell.
Make sure to “reply to all”.
cu,
Friedrich
plt.axis(‘off’)
or
ax = plt.gca()
ax.set_axis_off()
should clear the axis bounds and remove ticks as well.
···
On Thu, Nov 24, 2011 at 7:57 AM, Marianne C. <mariyanna.c@…287…> wrote:
My name is Marianne, I am a beginner user of matplotlib.
I am using imshow in pyplot. I am desperate to get rid of
the ticks on both x and y axes (see attached picture). I
do not need the black box around the data either. Should
I use imshow in axes.Axes instead, to be able to call
–
Gökhan
There are a number of ways to accomplish this, but the one I use is to make the x and y axes invisible (gets rid of the ticks) and also make the spines invisible (gets rid of the lines). I just throw these changes into a utility function (clear_frame
below) and put that in a module that’s on my python path so that it’s easily reusable.
Hope that helps,
-Tony
···
On Thu, Nov 24, 2011 at 9:48 AM, Marianne C. <mariyanna.c@…83…287…> wrote:
Hi all,
My name is Marianne, I am a beginner user of matplotlib.
I am using imshow in pyplot. I am desperate to get rid of
the ticks on both x and y axes (see attached picture). I
do not need the black box around the data either. Should
I use imshow in axes.Axes instead, to be able to call
set_ticks_position("none")?
Thank you for your help,
Marianne
Here is the code so far:
import numpy
from matplotlib import pyplot
q=numpy.loadtxt(‘field.txt’)
myfield = pyplot.imshow(q,aspect=1)
myfield.set_clim(vmin=0, vmax=0.6)
pyplot.colorbar()
pyplot.savefig(‘field_1.eps’)
#~~~
import numpy as np
import matplotlib.pyplot as plt
def clear_frame(ax=None):
if ax is None:
ax = plt.gca()
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
for spine in ax.spines.itervalues():
spine.set_visible(False)
img = np.random.random((100,100))
plt.imshow(img)
clear_frame()
plt.colorbar()
plt.show()
#~~~
Thank you so much, Gökhan! That’s exactly what I was looking for.
Best,
Marianne
···
On Fri, Nov 25, 2011 at 6:39 PM, Gökhan Sever <gokhansever@…287…> wrote:
plt.axis(‘off’)
or
ax = plt.gca()
ax.set_axis_off()
should clear the axis bounds and remove ticks as well.