Skip to content

[Bug]: Strange errorbar caps when polar axes have non-default theta direction or theta zero location #28885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Hem-W opened this issue Sep 25, 2024 · 11 comments · Fixed by #28966

Comments

@Hem-W
Copy link

Hem-W commented Sep 25, 2024

Bug summary

For the projection="polar" axes that are set to use a different theta direction or theta zero location other than the default, the caps of ax.errorbar would be rotated strangely.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

theta = np.arange(0, 2 * np.pi, np.pi / 8)
r = theta / np.pi / 2 + 0.5

fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(projection='polar')
ax.errorbar(theta, r, xerr=0.1, yerr=0.1, capsize=7, fmt="o", c="seagreen")
ax.set_title("Pretty polar error bars")
ax.set_theta_zero_location("N")
ax.set_theta_direction(-1)
plt.show()

Actual outcome

output

Expected outcome

The caps of error bars are expected to be still perpendicular to the error bar lines.

Additional information

No response

Operating system

Ubuntu 20.04

Matplotlib Version

3.9.1

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.9.18

Jupyter version

No response

Installation

conda

@timhoffm
Copy link
Member

timhoffm commented Sep 25, 2024

It seems errorbar caps currently do not account for a changed orientation due to theta_zero_location nor due to theta_zero_direction. Their angle stays the same as for the unmodifed plot.

The fix (add appropriate sign and offset) should likely be around here:

# Rotate caps to be perpendicular to the error bars
for theta, r in zip(l.get_xdata(), l.get_ydata()):
rotation = mtransforms.Affine2D().rotate(theta)
if axis == 'y':
rotation.rotate(-np.pi / 2)
ms = mmarkers.MarkerStyle(marker=marker,
transform=rotation)
self.add_line(mlines.Line2D([theta], [r], marker=ms,
**eb_cap_style))

This is a good first issue, because the fix is straight forward and easy to verify.

@timhoffm timhoffm added status: confirmed bug topic: polar Good first issue Open a pull request against these issues if there are no active ones! labels Sep 25, 2024
Copy link

Good first issue - notes for new contributors

This issue is suited to new contributors because it does not require understanding of the
Matplotlib internals. To get started, please see our contributing
guide
.

We do not assign issues. Check the Development section in the sidebar for linked pull
requests (PRs). If there are none, feel free to start working on it. If there is an open PR, please
collaborate on the work by reviewing it rather than duplicating it in a competing PR.

If something is unclear, please reach out on any of our communication
channels
.

@campout12
Copy link

I’d love to give this issue a try and work on the fix!

@timhoffm
Copy link
Member

timhoffm commented Sep 25, 2024

@johnsonhsiung Got for it!

Tipp: use PolarAxes.get_theta_offset and PolarAxes.get_theta_direction to obtain the relevant numbers to include into the calculation.

@campout12
Copy link

I ran into a problem while trying to setup. I'm currently following this guide: https://matplotlib.org/devdocs/devel/contribute.html

While running this command
python -m pip install --no-build-isolation --editable .[dev]

I got this error which was an easy fix by running pip install ninja.
meson-python: error: Could not find ninja version 1.8.2 or newer.

However, after running again the command again, I was hit with a longer error

Obtaining file:///E:/opensource/matplotlib
  Checking if build backend supports build_editable ... done
  Preparing editable metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [22 lines of output]
      + meson setup E:\opensource\matplotlib E:\opensource\matplotlib\build\cp312 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=E:\opensource\matplotlib\build\cp312\meson-python-native-file.ini
      The Meson build system
      Version: 1.5.2
      Source dir: E:\opensource\matplotlib
      Build dir: E:\opensource\matplotlib\build\cp312
      Build type: native build
      Program python3 found: YES
      Project name: matplotlib
      Project version: 0.1.0.dev51091+g69f09d1
      C compiler for the host machine: gcc (gcc 6.3.0 "gcc (MinGW.org GCC-6.3.0-1) 6.3.0")
      C linker for the host machine: gcc ld.bfd 2.28
      C++ compiler for the host machine: c++ (gcc 6.3.0 "c++ (MinGW.org GCC-6.3.0-1) 6.3.0")
      C++ linker for the host machine: c++ ld.bfd 2.28
      Host machine cpu family: x86
      Host machine cpu: x86
      Program python found: YES (E:\opensource\matplotlib\myenv\Scripts\python.exe)
      Need python for x86, but found x86_64
      Run-time dependency python found: NO (tried sysconfig)

      ..\..\meson.build:37:14: ERROR: Python dependency not found

      A full log can be found at E:\opensource\matplotlib\build\cp312\meson-logs\meson-log.txt
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

I tried looking around online and was told to install from these two sites:

  1. https://sourceforge.net/projects/mingw/
  2. https://developer.arm.com/downloads/-/gnu-rm

I installed them, deleted my virtual env, and repeated the steps, but still receive the same error. Any ideas on how to proceed?
Thank you!

Also, here's the full log: meson-log.txt

@timhoffm
Copy link
Member

Sorry, I cannot help setting up the compiler infrastructure on Windows. That's not my OS for development.

@timhoffm
Copy link
Member

You may alternatively try GitHub Codespaces so that you don't have to do any local setup:

image

@markovas1ljevic
Copy link

I'd like to work on this issue if possible! Newcomer so I may need some assistance.

@markovas1ljevic
Copy link

markovas1ljevic commented Sep 26, 2024

image
Hope that this resolves the issue!

@story645
Copy link
Member

@cdubUF cdubUF mentioned this issue Oct 4, 2024
5 tasks
@rcomer rcomer removed the Good first issue Open a pull request against these issues if there are no active ones! label Oct 5, 2024
@rcomer
Copy link
Member

rcomer commented Oct 5, 2024

Removed the Good first issue label. Partly in hope to not attract any more duplicate PRs, but also because I think the discussion in #28905 is beyond the first issue level!

@QuLogic QuLogic linked a pull request Oct 12, 2024 that will close this issue
2 tasks
@QuLogic QuLogic added this to the v3.10.0 milestone Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment