X Tutup
Skip to content

MaxNLocator prune isn't working with decimals #8425

@kannkann

Description

@kannkann

Bug report

Using MaxNLocator with the prune='both' option should remove the upper and lower ticks. This does not work with decimal ticks. Probably because of rounding or something related with binary numbers.

Temporarily I fixed it for me by shifting the limits slightly instead of using prune.
axes.set(ylim=[axes.get_ylim()[0]*0.99999,axes.get_ylim()[1]*1.00001])

import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
fig,axes= plt.subplots(1,2)
axes[0].plot([0,4],[0.2,0.3])
axes[0].yaxis.set_major_locator(mtick.MaxNLocator(nbins=6, prune='both'))
print(axes[0].get_ylim())
axes[1].plot([0,4],[2,3])
axes[1].yaxis.set_major_locator(mtick.MaxNLocator(nbins=6, prune='both'))
print(axes[1].get_ylim())
plt.show()

Actual outcome
image

Expected outcome
(see right subplot)

Matplotlib version
Matplotlib 1.5.3
Python: 3.5.2 |Anaconda custom (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]

I hope I did everything right and this is helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup