Skip to content

Option for adding errorbar legend #440

Open

Description

@kinyatoride

Description

Hi, I think it will be great if we have an option to show error bar in the legend similar to what shade and fade do.

Current behavior

Currently, we cannot show error bar in the legend. Only the line is shown in the left figure.

import numpy as np
import pandas as pd
import proplot as pplt

state = np.random.RandomState(51423)
data = state.rand(20, 8).cumsum(axis=0).cumsum(axis=1)[:, ::-1]
data = data + 20 * state.normal(size=(20, 8)) + 30
data = pd.DataFrame(data, columns=np.arange(0, 16, 2))

fig, axs = pplt.subplots(ncols=2)

ax = axs[0]
h = ax.plot(data, means=True, label='label')
ax.legend(h)

ax = axs[1]
h = ax.plot(data, means=True, shadestd=1, label='label')
ax.legend(h)

output

Proplot version

3.4.3
0.9.7

Activity

  1. cvanelteren commented on Aug 8, 2024

    @cvanelteren

    You mean like this:
    image

    see here

    import numpy as np
    import pandas as pd
    import proplot as pplt
    
    state = np.random.RandomState(51423)
    data = state.rand(20, 8).cumsum(axis=0).cumsum(axis=1)[:, ::-1]
    data = data + 20 * state.normal(size=(20, 8)) + 30
    data = pd.DataFrame(data, columns=np.arange(0, 16, 2))
    
    fig, ax = pplt.subplots()
    
    h = ax.imshow(np.random.rand(10, 10))
    ax.colorbar(h, loc="upper right")
    pplt.show(block=1)
    
  2. kinyatoride commented on Aug 8, 2024

    @kinyatoride
    Author

    Not actually... That's a colorbar. The error bar is not shown in the legend in my original left figure.

  3. cvanelteren commented on Aug 8, 2024

    @cvanelteren

    Ah my bad I read your original question wrong! Use errorbar instead

    import numpy as np
    import pandas as pd
    import proplot as pplt
    
    state = np.random.RandomState(51423)
    data = state.rand(20, 8).cumsum(axis=0).cumsum(axis=1)[:, ::-1]
    data = data + 20 * state.normal(size=(20, 8)) + 30
    data = pd.DataFrame(data, columns=np.arange(0, 16, 2))
    
    fig, ax = pplt.subplots()
    x = np.linspace(0, 10)
    y = x
    yerr = abs(np.random.randn(x.size))
    h = ax.errorbar(x, y, yerr=yerr, label="test")
    ax.legend()
    pplt.show(block=1)
  4. cvanelteren commented on Aug 8, 2024

    @cvanelteren

    image
    For completeness

  5. kinyatoride commented on Aug 8, 2024

    @kinyatoride
    Author

    Thanks. My suggestion was to include that option with ax.plot(data, means=True).
    Currently, it is supported when you show errors with shading or fading options e.g. ax.plot(data, means=True, shadestd=1).

    That way, it will be more consistent.

  6. cvanelteren commented on Aug 8, 2024

    @cvanelteren

    I see that is a bit inconsistent indeed. I can put this on the stack of todos. Should be an easy fix.

  7. cvanelteren commented on Aug 9, 2024

    @cvanelteren

    Note to-self:

    • Extract and pass label to error bar in plot.py @ 1506
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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