Is there a way to turn of xticks and yticks using matplotlibrc or another matplotlib config method? The only way I see currently is to set the sizes of ticks and tick labels to zero. That seems an odd way, given that I can set_xticks(())
You can do this with tick_params
plt.tick_params(axis='both', which='both')
This is affecting both axis (other options are x or y). It also affects both major and minor ticks (other options are major or minor)
This will leave ticks around the outer edge, but not in the plot. If you want the edge ticks removed, you can add:
bottom='off'
top='off'
left='off'
right='off'
If you want to remove the labels, you'll want to turn these off
labelbottom='off'
labeltop='off'
labelleft='off'
labelright='off'
Related
I have a contour plot and I am using matplotlib to change my axes limits, from 128 to 100. But when I do this, it "cuts" my plot. The first plot is what I have in the beginning and the second one is what I take after changing the limits. Could someone tell me how it's possible just to modify the limits of the axes without changing at all, the form of the plot? [
1]: https://i.stack.imgur.com/9SV5e.png
Pretty simple, I want minor ticks on my subplot on the xaxis, but not the yaxis. I've tried all sorts (there seem to be hundreds of methods for ticks) but all seem to want me to specify the locations for the ticks, or use a TickLocator. I just want them on, and not to have to specify where (just like how the Major ticks work automatically).
Something like:
axis.set_minor_xticks_on()
or
axis.xaxis.set_minor_ticks()
or
axis.set_ticks(which='minor', True)
seems so simple but these don't work and I can't seem to find an equivalent. Surely there is one? I don't want labels on the minor ticks.
Using Python 3.5.2 and Matplotlib 1.5.3
I managed to achieve what I wanted to achieve with:
ax.minorticks_on()
ax.tick_params(axis='x', which='minor', direction='out')
Some code gives me the following matplotlib figure:
Unfortunately, the figure size is fixed and hence on the top right, the legend and the lines overlap. Is there any way to have the legend not stack on top of the lines?
I am aware that legend allows ax2.legend(loc=0), where 0 will put it into the "best" location. However, with two y axis as here, this will stack both legends on top of each other - not really the best allocation.
My next best try would be to "scale up" the figure, as manually done with an interactive graph, where I have only scaled up both axis:
Doing this with the "real" figure scale requires iterated "trying numbers and checking how far it goes" procedure - which may need to be redone if the graph changes. Is there any way of having matplotlib compute the scale "intelligently"?
If the best location plt.legend(loc='best') fails, try putting the legend outside of the plot:
plt.legend(loc='upper left', bbox_to_anchor=(1.02, 1), borderaxespad=0)
You can scale only legend, not the whole plot. Link here
More on legends here and also here.
I have a plot with an Axes, and I call:
axes.set_xscale('log')
After that I cannot see any tick label along the x axis, when I use axes.set_xticks(my_ticks). Without the log I can see the tick labels.
How can I show my ticks on the log scale?
axes.set_xticks(my_ticks) sets the position of the ticks, it normally automatically updates the tick labels, but it seems it doesn't. You can use set_xticklabels() to set them yourself.
You can use tick_params() to change properties of the ticks (like length, color etc) themselves.
I have a matplotlib axes instance inside which I'm animating an AxesImage via blitting.
What I'd like to do is animate the ticks on the x-axis as well.
I am updating the data on the AxesImage (and subsequently) drawing its artist quite frequently, and on each update I'd like to move one extra tick placed to highlight the position of something.
This is what I'm doing right now:
axis = axes.get_xaxis
im.set_data(new_data)
axis.set_ticks([10,20,30,x,t])
axis.set_ticklabels(["p", "u", "z", "z", "i"])
axes.draw_artist(im)
axes.draw_artist(axis)
While I see the ticks correctly updating, the labels are not. I think that the axes bbox does not include the axes, is this possible? If so, how can I animate it? Should I copy and restore from somewhere else?
The axes bbox doesn't include anything outside of the "inside" of the axes (e.g. it doesn't include the tick labels, title, etc.)
One quick way around this is to just grab the entire region of the figure when you're blitting. (E.g. background = canvas.copy_from_bbox(fig.bbox))
This can cause problems if you have multiple subplots and only want to animate one of them. In that case, you can do something along the lines of background = canvas.copy_from_bbox(ax.bbox.expanded(1.1, 1.2)). You'll have to guesstimate the ratios you need, though.
If you need the exact extent of the tick labels, it's a bit trickier. The easiest way is to iterate through the ticklabel objects and get the union with ax.bbox. You can make this a one-liner: ax.bbox.union([label.get_window_extent() for label in ax.get_xticklabels()]).
At any rate, one of those three options should do what you need, I think.