0

I am looking at the below example with parasite axis https://matplotlib.org/2.0.2/examples/axes_grid/demo_parasite_axes2.html

How do I remove both the xticks and yticks from that example?

I am aware of plt.tick_params but that didn't work for me. i.e. I tried

plt.tick_params(axis='x',which='both',bottom=False,top=False)

but that didnt work. Could someone help please?

user13412850
  • 509
  • 1
  • 5
  • 16

2 Answers2

0

If this plot is what you are trying to achieve: enter image description here

You add these lines to the code:

host.set_xticks([])
host.set_yticks([])
pakpe
  • 5,391
  • 2
  • 8
  • 23
  • thanks @pakpe, what I meant was I want to see the values on x and y axis without those annoying small tick bars protruding inside ( if I could express myself clearly) – user13412850 May 20 '21 at 00:15
  • You cannot. You can hide the tick marks and the tick labels together. You can also hide just the tick labels. However, you can not hide the tick marks alone. Honestly, I don't know why you would want to. If you have ticks labels, you need to have tick marks - that's just standard plotting convention. – pakpe May 20 '21 at 00:34
  • @pakpe - I believe you can hide ticks marks alone, for example with `host.tick_params(width=0)`. – BigBen May 20 '21 at 00:44
  • @BigBen. Thank you. I learned something. Upon further reflection, I think OP may want to just hide the ticks on the top axis, though. – pakpe May 20 '21 at 00:52
  • Yeah I wasn't sure which ticks to hide. Also another issue is that `par1.set_ylabel("Temperature")` is not successfully setting the ylabel on the secondary y-axis, the label is being obscured by something. – BigBen May 20 '21 at 00:54
  • @BigBen Yes, I also noticed that about the Temp axis. A more interesting question would be how to fix that problem. Any ideas? – pakpe May 20 '21 at 00:57
  • `par1.get_ylabel()` returns `Temperature` ... so investigating further. – BigBen May 20 '21 at 00:58
  • 2
    @BigBen. I figured it out. You have to repeat the 3 lines of code starting at new_fixed_axis for par1 and leave the offset at 0,0. – pakpe May 20 '21 at 03:28
0

IIUC, I believe you can use tick_params(width=0). Adjust the below as necessary depending on which ticks you want to hide.

host.tick_params(width=0)
par1.tick_params(width=0)
par2.tick_params(width=0)

Output:

enter image description here

BigBen
  • 46,229
  • 7
  • 24
  • 40