Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Rectangle patch not transformed correctly in polar plot #8521

Open
@alexvorndran

Description

@alexvorndran

Bug summary
I added some rectangular patches to a polar plot and found that they are not transformed correctly if those patches are the only objects plotted. However, if there is any plot like a polar bar plot on the same figure, all patches on this and following figures are displayed correctly. As you can see in the code below, this behaviour can be observed even if the "other" plot is removed immediately.

Please note that this will only work on a "fresh" IPython/python console where no bar/scatter/... plot has been done on a polar axis, as all subsequent attempts will produce the correct result.

Code for reproduction

Putting plt.show() at the very end of the script instead of where it is in the snippet does not lead to the error described above.

# -*- coding: utf-8 -*-
import math

import matplotlib.pyplot as plt
from matplotlib import patches


def polarbug(bar_hack=False):
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='polar')

    # add quadrant as example
    ax.add_patch(
        patches.Rectangle(
            (0, 1), width=math.pi*0.5, height=0.5
        )
    )

    if bar_hack:
        ax.bar(0, 1).remove()

    ax.set_rmax(2)
    plt.show()


if __name__ == '__main__':
    polarbug()
    polarbug(bar_hack=True)
    polarbug()

Actual outcome
With (left) and without (right) ax.set_rmax(2):
Figure 1
polarbug-1 polarbug-1-w

Figure 2
polarbug-2 polarbug-2-w

Figure 3
polarbug-3 polarbug-3-w

Expected outcome
All three figures should look the same.

Matplotlib version

  • Operating System: Windows 10 Pro x64
  • Matplotlib Version: 2.0.0 (conda 4.3.16)
  • Python Version: 2.7.13 64bit
  • Other Libraries: math or numpy (for pi only)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions