8000 `basic_units.py` doesn't display negative radians correctly · Issue #11531 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
basic_units.py doesn't display negative radians correctly #11531
Closed
@Harnesser

Description

@Harnesser

Bug report

Bug summary

Changing the example radian_ticks.py to plot a waveform from a negative to positive radians range displays incorrect tick labels.

    x = [val*radians for val in np.arange(-7, 8, 0.01)]

original_neg_radians

The issues:

  1. "0" is repeated
  2. "-1pi/2" should just be "-pi/2"
  3. The negative labels are just wrong

Fix
Change rad_fn() in basic_units.py:

# radians formatting
def rad_fn(x, pos=None):
    if x >= 0:
        n = int((x / np.pi) * 2.0 + 0.25)
    else:
        n = int((x / np.pi) * 2.0 - 0.25)
        
    if n == 0:
        return '0'
    elif n == 1:
        return r'$\pi/2$'
    elif n == 2:
        return r'$\pi$'
    elif n == -1:
        return r'$-\pi/2$'
    elif n == -2:
        return r'$-\pi$'
    elif n % 2 == 0:
        return r'$%s\pi$' % (n//2,)
    else:
        return r'$%s\pi/2$' % (n,)

fixed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0