Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to simultaneously remove top and right axes and plot ticks facing outwards?
    primarykey
    data
    text
    <p>I would like to make a matplotlib plot having only the left and bottom axes, and also the ticks facing outwards and not inwards as the default. I found two questions that address both topics separately:</p> <ul> <li><p><a href="https://stackoverflow.com/questions/6260055/matplotlib-drawing-r-style-axis-ticks-that-extend-outward-from-the-axes">In matplotlib, how do you draw R-style axis ticks that point outward from the axes?</a></p></li> <li><p><a href="https://stackoverflow.com/questions/925024/how-can-i-remove-the-top-and-right-axis-in-matplotlib">How can I remove the top and right axis in matplotlib?</a></p></li> </ul> <p>Each of them work on its own, but unfortunately, both solutions seem to be incompatible with each other. After banging my head for some time, I found a warning in <a href="http://matplotlib.github.com/mpl_toolkits/axes_grid/" rel="nofollow noreferrer">the <code>axes_grid</code> documentation</a> that says </p> <blockquote> <p>"some commands (mostly tick-related) do not work"</p> </blockquote> <p>This is the code that I have:</p> <pre><code>from matplotlib.pyplot import * from mpl_toolkits.axes_grid.axislines import Subplot import matplotlib.lines as mpllines import numpy as np #set figure and axis fig = figure(figsize=(6, 4)) #comment the next 2 lines to not hide top and right axis ax = Subplot(fig, 111) fig.add_subplot(ax) #uncomment next 2 lines to deal with ticks #ax = fig.add_subplot(111) #calculate data x = np.arange(0.8,2.501,0.001) y = 4*((1/x)**12 - (1/x)**6) #plot ax.plot(x,y) #do not display top and right axes #comment to deal with ticks ax.axis["right"].set_visible(False) ax.axis["top"].set_visible(False) #put ticks facing outwards #does not work when Sublot is called! for l in ax.get_xticklines(): l.set_marker(mpllines.TICKDOWN) for l in ax.get_yticklines(): l.set_marker(mpllines.TICKLEFT) #done show() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload