diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml deleted file mode 100644 index c64e6387..00000000 --- a/.github/workflows/cd.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: CD - -on: - workflow_dispatch: - pull_request: - branches: - - master - release: - types: - - published - -jobs: - dist: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Build wheel and SDist - run: pipx run build - - - uses: actions/upload-artifact@v3 - with: - path: dist/* - - - name: Check metadata - run: pipx run twine check dist/* - - - publish: - needs: [dist] - runs-on: ubuntu-latest - if: github.event_name == 'release' && github.event.action == 'published' - - steps: - - uses: actions/download-artifact@v3 - with: - name: artifact - path: dist - - - uses: pypa/gh-action-pypi-publish@v1.8.5 - with: - password: ${{ secrets.pypi_password }} - print-hash: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index c68b9fcb..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: CI - -on: - push: - branches: - - 'master*' - pull_request: - # Run daily at 0:01 UTC - schedule: - - cron: '1 0 * * *' - -jobs: - - test: - name: "🐍 ${{ matrix.python-version }} • ${{ matrix.runs-on }}" - runs-on: ${{ matrix.runs-on }} - strategy: - matrix: - runs-on: [ubuntu-latest] - python-version: ["3.8", "3.10", "3.11"] - include: - - runs-on: macOS-latest - python-version: "3.8" - - runs-on: macOS-latest - python-version: "3.11" - - steps: - - uses: actions/checkout@v3 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Install core fonts - if: runner.os == 'Linux' - run: | - echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections - sudo apt-get install ttf-mscorefonts-installer - - - name: Install dependencies - run: | - python -m pip install --upgrade pip setuptools wheel pytest-github-actions-annotate-failures - python -m pip install -q --no-cache-dir -e .[all] - python -m pip list - - - name: Test with pytest - run: | - python -m pytest -r sa --mpl --mpl-results-path=pytest_results - - - name: Upload pytest test results - uses: actions/upload-artifact@v3 - if: failure() - with: - name: pytest_results-${{ matrix.python-version }}-${{ matrix.runs-on }} - retention-days: 3 - path: pytest_results diff --git a/.github/workflows/head-dependencies.yml b/.github/workflows/head-dependencies.yml deleted file mode 100644 index 99d720fb..00000000 --- a/.github/workflows/head-dependencies.yml +++ /dev/null @@ -1,187 +0,0 @@ -name: HEAD of dependencies - -on: - # Run daily at 1:23 UTC - schedule: - - cron: '23 1 * * *' - workflow_dispatch: - -jobs: - release-candidates: - - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - python-version: ['3.11'] - - steps: - - uses: actions/checkout@v3 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Install core fonts - if: runner.os == 'Linux' - run: | - echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections - sudo apt-get install ttf-mscorefonts-installer - - - name: Install dependencies - run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip install pytest-github-actions-annotate-failures - python -m pip --quiet install --upgrade --pre .[test] - - - name: List installed Python packages - run: python -m pip list - - - name: Test with pytest - run: | - pytest -r sa --mpl --mpl-results-path=pytest_results - - - name: Upload pytest test results - uses: actions/upload-artifact@v3 - if: failure() - with: - name: pytest_results-${{ matrix.python-version }}-${{ matrix.runs-on }} - retention-days: 3 - path: pytest_results - - matplotlib: - - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest] - python-version: ['3.11'] - - steps: - - uses: actions/checkout@v3 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Install core fonts - run: | - echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections - sudo apt-get install ttf-mscorefonts-installer - - - name: Install dependencies - run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip install pytest-github-actions-annotate-failures - python -m pip --no-cache-dir --quiet install --upgrade .[test] - python -m pip install \ - --upgrade \ - --pre \ - --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \ - --extra-index-url https://pypi.org/simple/ \ - matplotlib - - - name: List installed Python packages - run: python -m pip list - - - name: Test with pytest - run: | - pytest -r sa --mpl --mpl-results-path=pytest_results - - - name: Upload pytest test results - uses: actions/upload-artifact@v3 - if: failure() - with: - name: pytest_results-${{ matrix.python-version }}-${{ matrix.runs-on }} - retention-days: 3 - path: pytest_results - - uhi: - - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest] - python-version: ['3.11'] - - steps: - - uses: actions/checkout@v3 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Install core fonts - run: | - echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections - sudo apt-get install ttf-mscorefonts-installer - - - name: Install dependencies - run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip install pytest-github-actions-annotate-failures - python -m pip --no-cache-dir --quiet install --upgrade .[test] - python -m pip uninstall --yes uhi - python -m pip install --upgrade git+https://github.com/scikit-hep/uhi.git - - - name: List installed Python packages - run: python -m pip list - - - name: Test with pytest - run: | - pytest -r sa --mpl --mpl-results-path=pytest_results - - - name: Upload pytest test results - uses: actions/upload-artifact@v3 - if: failure() - with: - name: pytest_results-${{ matrix.python-version }}-${{ matrix.runs-on }} - retention-days: 3 - path: pytest_results - - pytest: - - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest] - python-version: ['3.11'] - - steps: - - uses: actions/checkout@v3 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Install core fonts - run: | - echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections - sudo apt-get install ttf-mscorefonts-installer - - - name: Install dependencies - run: | - python -m pip install --upgrade pip setuptools wheel - python -m pip install pytest-github-actions-annotate-failures - python -m pip --no-cache-dir --quiet install --upgrade .[test] - python -m pip uninstall --yes pytest - python -m pip install --upgrade git+https://github.com/pytest-dev/pytest.git - - - name: List installed Python packages - run: python -m pip list - - - name: Test with pytest - run: | - pytest -r sa --mpl --mpl-results-path=pytest_results - - - name: Upload pytest test results - uses: actions/upload-artifact@v3 - if: failure() - with: - name: pytest_results-${{ matrix.python-version }}-${{ matrix.runs-on }} - retention-days: 3 - path: pytest_results diff --git a/src/mplhep/plot.py b/src/mplhep/plot.py index 3c1c40b4..1de1326d 100644 --- a/src/mplhep/plot.py +++ b/src/mplhep/plot.py @@ -233,7 +233,7 @@ def histplot( elif flow == "hint": plottables.append(Plottable(value, edges=final_bins, variances=variance)) elif flow == "show": - if underflow > 0: + if underflow != 0: if i == 0: flow_bins = np.insert( final_bins, @@ -249,7 +249,7 @@ def histplot( value, variance = np.insert( value, 0, h.values(flow=True)[0] ), np.insert(value, 0, h.variances(flow=True)[0]) - if overflow > 0: + if overflow != 0: if i == 0: flow_bins = np.append( flow_bins, @@ -509,7 +509,7 @@ def iterable_not_string(arg): if x_axes_label: ax.set_xlabel(x_axes_label) - if flow in {"hint", "show"} and (underflow > 0.0 or overflow > 0.0): + if flow in {"hint", "show"} and (underflow != 0.0 or overflow != 0.0): d = 0.9 # proportion of vertical to horizontal extent of the slanted line trans = mpl.transforms.blended_transform_factory(ax.transData, ax.transAxes) ax_h = ax.bbox.height @@ -524,7 +524,7 @@ def iterable_not_string(arg): transform=trans, ) xticks = ax.get_xticks().tolist() - if underflow > 0.0: + if underflow != 0.0: if flow == "hint": ax.plot( [ @@ -544,7 +544,7 @@ def iterable_not_string(arg): xticks[1] = f"<{flow_bins[2]}" ax.set_xticklabels(xticks) - if overflow > 0.0: + if overflow != 0.0: if flow == "hint": ax.plot( [ @@ -668,7 +668,7 @@ def hist2dplot( print(f"Warning: you don't have flow bins stored in {h}") elif flow == "show": H = h.values(flow=True) - if any(h.values(flow=True)[0] > 0): + if any(h.values(flow=True)[0] != 0): xbins = np.array( [ xbins[0] - (xbins[-1] - xbins[0]) * 0.08, @@ -676,7 +676,10 @@ def hist2dplot( *xbins, ] ) - if any(h.values(flow=True)[-1] > 0): + H = np.insert(H, (1), np.full(np.shape(H)[1], np.nan), axis=0) + else: + H = H[1:] + if any(h.values(flow=True)[-1] != 0): xbins = np.array( [ *xbins, @@ -684,7 +687,10 @@ def hist2dplot( xbins[-1] + (xbins[-1] - xbins[0]) * 0.08, ] ) - if any(h.values(flow=True)[:, 0] > 0): + H = np.insert(H, (-1), np.full(np.shape(H)[1], np.nan), axis=0) + else: + H = H[:-1] + if any(h.values(flow=True)[:, 0] != 0): ybins = np.array( [ ybins[0] - (ybins[-1] - ybins[0]) * 0.08, @@ -692,7 +698,10 @@ def hist2dplot( *ybins, ] ) - if any(h.values(flow=True)[:, -1] > 0): + H = np.insert(H, (1), np.nan, axis=-1) + else: + H = H[:, 1:] + if any(h.values(flow=True)[:, -1] != 0): ybins = np.array( [ *ybins, @@ -700,15 +709,9 @@ def hist2dplot( ybins[-1] + (ybins[-1] - ybins[0]) * 0.08, ] ) - - if any(h.values(flow=True)[0] > 0.0): - H = np.insert(H, (1), np.nan, axis=-1) - if any(h.values(flow=True)[-1] > 0.0): H = np.insert(H, (-1), np.nan, axis=-1) - if any(h.values(flow=True)[:, 0] > 0): - H = np.insert(H, (1), np.full(np.shape(H)[1], np.nan), axis=0) - if any(h.values(flow=True)[:, -1] > 0): - H = np.insert(H, (-1), np.full(np.shape(H)[1], np.nan), axis=0) + else: + H = H[:, :-1] elif flow == "sum": H = h.values().copy() # Sum borders @@ -794,7 +797,7 @@ def hist2dplot( mew=1, clip_on=False, ) - if any(h.values(flow=True)[0] > 0): + if any(h.values(flow=True)[0] != 0): if flow == "hint": ax.plot( [ @@ -806,9 +809,12 @@ def hist2dplot( **kwargs, ) if flow == "show": + ax.plot([xbins[1], xbins[2]], [ybins[-1], ybins[-1]], **kwargs) ax.plot([xbins[1], xbins[2]], [0, 0], transform=trans, **kwargs) - ax.plot([xbins[0], xbins[0]], [ybins[1], ybins[2]], **kwargs) - if any(h.values(flow=True)[:, 0] > 0): + xtick_labels = ax.get_xticklabels() + xtick_labels[0] = "" + ax.set_xticklabels(xtick_labels) + if any(h.values(flow=True)[:, 0] != 0): if flow == "hint": ax.plot( [ @@ -820,9 +826,12 @@ def hist2dplot( **kwargs, ) if flow == "show": - ax.plot([xbins[-3], xbins[-2]], [0, 0], transform=trans, **kwargs) + ax.plot([xbins[0], xbins[0]], [ybins[1], ybins[2]], **kwargs) ax.plot([xbins[-1], xbins[-1]], [ybins[1], ybins[2]], **kwargs) - if any(h.values(flow=True)[-1] > 0): + ytick_labels = ax.get_yticklabels() + ytick_labels[0], ytick_labels[1] = "", "" + ax.set_yticklabels(ytick_labels) + if any(h.values(flow=True)[-1] != 0): if flow == "hint": ax.plot( [ @@ -834,10 +843,10 @@ def hist2dplot( **kwargs, ) if flow == "show": - ax.plot([xbins[1], xbins[2]], [1, 1], transform=trans, **kwargs) ax.plot([xbins[0], xbins[0]], [ybins[-3], ybins[-2]], **kwargs) + ax.plot([xbins[-1], xbins[-1]], [ybins[-3], ybins[-2]], **kwargs) - if any(h.values(flow=True)[:, -1] > 0): + if any(h.values(flow=True)[:, -1] != 0): if flow == "hint": ax.plot( [ @@ -850,8 +859,10 @@ def hist2dplot( ) if flow == "show": ax.plot([xbins[-3], xbins[-2]], [1, 1], transform=trans, **kwargs) - ax.plot([xbins[-1], xbins[-1]], [ybins[-3], ybins[-2]], **kwargs) - + ax.plot([xbins[-3], xbins[-2]], [0, 0], transform=trans, **kwargs) + ytick_labels = ax.get_yticklabels() + ytick_labels[-2], ytick_labels[-1] = "", "" + ax.set_yticklabels(ytick_labels) _labels: np.ndarray | None = None if isinstance(labels, bool): _labels = H if labels else None