Giter Club home page Giter Club logo

Comments (4)

lukelbd avatar lukelbd commented on June 7, 2024 2

On second thought... even though this matplotlib example is weird it probably makes more sense to assign identical labels to each line rather than raising an error. That way users can easily assign labels, but prevent repeated legend entries by (e.g.) manually passing a single line handle to legend(). I'll re-open

from proplot.

lukelbd avatar lukelbd commented on June 7, 2024

Makes sense. Maybe that should be the default behavior when label is used instead of labels (currently they are aliases)? For now here's a clumsy workaround:

import numpy as np
import proplot as pplt

state = np.random.RandomState(51423)
x = np.linspace(0, 5, 20)
y1 = x[:, np.newaxis] + state.rand(20, 10)
y2 = x[::-1, np.newaxis] + state.rand(20, 10)

fig, ax = pplt.subplots()
ax.plot(y1, c='r', label=['y1'] + 9 * [None])
ax.plot(y2, c='b', label=['y2'] + 9 * [None])
ax.legend()

iTerm2 UKZCDv tmp58qbkxgz

from proplot.

kinyatoride avatar kinyatoride commented on June 7, 2024

On second thought, this might cause unexpected behavior. We need to specify a color (and other properties) for the group of lines. If we pass a single label without specifying a color, it won't know which color to use for the legend.
We could use the property of the first line, but I don't know if this is a good idea.

from proplot.

lukelbd avatar lukelbd commented on June 7, 2024

Hmm yeah I can see that. And actually this is matplotlib's default behavior :/... not sure if any better than current proplot behavior of raising an error. Think I'll close then

import numpy as np
import matplotlib.pyplot as plt

state = np.random.RandomState(51423)
x = np.linspace(0, 5, 20)
y1 = x[:, np.newaxis] + state.rand(20, 10)
y2 = x[::-1, np.newaxis] + state.rand(20, 10)

fig, ax = plt.subplots()
ax.plot(y1, c='r', label='y1')
ax.plot(y2, c='b', label='y2')
ax.legend()

iTerm2 EYQgA4 tmpjutgkpek

from proplot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.