Skip to content
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

width = max([len(line) for c in self._content for line in c]) No content in figure #43

Closed
hudengjunai opened this issue Apr 28, 2020 · 10 comments

Comments

@hudengjunai
Copy link

hudengjunai commented Apr 28, 2020

import termplotlib as tpl
import numpy

x = numpy.linspace(0, 2 * numpy.pi, 10)
y = numpy.sin(x)

fig = tpl.figure()
fig.plot(x, y, label="data", width=50, height=15)
fig.show()

after run this piece of code ,there are error ,

if self._width is None:
---> 33             width = max([len(line) for c in self._content for line in c])
     34             width += padding_lr
     35         else:

did you come up with this problem?

@nschloe
Copy link
Owner

nschloe commented Apr 28, 2020

Cannot reproduce:

    1 +---------------------------------------+
  0.8 |    **     **                          |
  0.6 |   *         **           data ******* |
  0.4 | **                                    |
  0.2 |*              **                      |
    0 |                 **                    |
      |                                   *   |
 -0.2 |                   **            **    |
 -0.4 |                     **         *      |
 -0.6 |                              **       |
 -0.8 |                       **** **         |
   -1 +---------------------------------------+
      0     1    2     3     4     5    6     7

@rockt
Copy link

rockt commented Apr 28, 2020

I have the same issue

Python 3.7.4 (default, Aug 13 2019, 15:17:50)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import termplotlib as tpl
>>> import numpy
>>>
>>> x = numpy.linspace(0, 2 * numpy.pi, 10)
>>> y = numpy.sin(x)
>>>
>>> fig = tpl.figure()
>>> fig.plot(x, y, label="data", width=50, height=15)
>>> fig.show()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/.../python3.7/site-packages/termplotlib/figure.py", line 24, in show
    print(self.get_string())
  File "/Users/.../python3.7/site-packages/termplotlib/figure.py", line 33, in get_string
    width = max([len(line) for c in self._content for line in c])
ValueError: max() arg is an empty sequence

@nschloe
Copy link
Owner

nschloe commented Apr 28, 2020

Please make your code copy-pastable.

@rockt
Copy link

rockt commented Apr 29, 2020

import termplotlib as tpl
import numpy

x = numpy.linspace(0, 2 * numpy.pi, 10)
y = numpy.sin(x)

fig = tpl.figure()
fig.plot(x, y, label="data", width=50, height=15)
fig.show()

@nschloe
Copy link
Owner

nschloe commented Apr 29, 2020

@rockt This is literally the same thing that OP posted. 👎

@rockt
Copy link

rockt commented Apr 29, 2020

Indeed, even better: it's the example from the project's README. The reason I commented on this issue is for you to see additional information on the error that both @hudengjunai and I get.

@nschloe
Copy link
Owner

nschloe commented Apr 29, 2020

Like I said: I cannot reproduce it, so I have no way of fixing it. PRs welcome!

@Farbdrucker
Copy link

Farbdrucker commented Dec 11, 2020

having the same issue with Python 3.7.6 termplotlib==0.2.4 with provided example

@t-springborn
Copy link

t-springborn commented Dec 28, 2020

The sourcecode in the github repository is not identical to the sourcecode installed by pip.
In figure.py line 31-35 are:

if self._width is None:
            line_lengths = [len(line) for c in self._content for line in c]
            width = max(line_lengths) if line_lengths else 0
            width += padding_lr

in the pip install it is:

if self._width is None:
            width = max([len(line) for c in self._content for line in c])
            width += padding_lr

This removes the check for empty content.

Fixing this still doesn't make it create a plot, but it removes the error message. I suspect there is another discrepancy somewhere.
@nschloe I assume this code discrepancy is why you couldn't reproduce the error.

@nschloe
Copy link
Owner

nschloe commented Feb 12, 2021

I pushed a new version (0.3.3) to pypi, and since I cannot reproduce the issue, I'll assume it's fixed somehow. Please reopen if this doesn't work for you.

@nschloe nschloe closed this as completed Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants