Code Monkey home page Code Monkey logo

Comments (13)

ivanprado avatar ivanprado commented on August 25, 2024 1

You have to remove the .tolist():

python3
Python 3.6.6 (default, Sep 12 2018, 18:26:19) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from asciichartpy import plot
>>> plot(np.arange(10))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ivan/Documentos/scrapinghub/dev/web-rcnn-venv/lib/python3.6/site-packages/asciichartpy/__init__.py", line 80, in plot
    if not series or all(isnan(n) for n in series):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
>>> 

from asciichart.

ivanprado avatar ivanprado commented on August 25, 2024 1

It works perfectly! Thank you @kroitor

from asciichart.

kroitor avatar kroitor commented on August 25, 2024 1

@ivanprado thx, appreciate your feedback!

from asciichart.

pkazmier avatar pkazmier commented on August 25, 2024 1

This fix has broken asciichartpy for me. Plotting a series of 0 values will now return an empty string instead of a graph with 0 values plotted:

>>> plot([0,0,0,0])
''

By using any, a regular python list of 0 values will evaluate as False.

The simple fix here is to change:

if not any(series) or all(isnan(n) for n in series):

to explicitly check for the length of the series:

if len(series) == 0 or all(isnan(n) for n in series):

from asciichart.

pkazmier avatar pkazmier commented on August 25, 2024 1

Works again, thanks for the instant turnaround!

from asciichart.

kroitor avatar kroitor commented on August 25, 2024

@ivanprado can you show your asciiplot definition plz?

from asciichart.

ivanprado avatar ivanprado commented on August 25, 2024

@kroitor what do you mean with asciiplot definition?

I forget to say that this is failing in the python version.

from asciichart.

kroitor avatar kroitor commented on August 25, 2024

@ivanprado i mean, it does not have an asciiiplot function that would accept 3 arguments as in your snippet. But, anyways, i think i'll upload a fix shortly. Thx!

from asciichart.

ivanprado avatar ivanprado commented on August 25, 2024

Ohh, you are right! Sorry I miss that. This is the function I'm using:

def asciiplot(y, width: int, height: int):
    """Return a string with a plot of the array as a nice ascii chart"""
    n = len(y)
    slice_size = n // width + bool(n % width)
    if n > width:
        y = np.pad(y, (0, slice_size * width - n), 'edge')
        y = y.reshape((-1, slice_size)).mean(axis=1)
    return asciichartpy.plot(y, {"height": height})

I'm converting the array to numpy, and this could be causing the problem in asciichartpy.

from asciichart.

kroitor avatar kroitor commented on August 25, 2024

@ivanprado thank you so much! Uploaded a fix to it, let me know if you have issues with version 1.15.12. Appreciate your help!

from asciichart.

ivanprado avatar ivanprado commented on August 25, 2024

@kroitor thank you for having time to look into that. I've tried version 1.15.12 and keeps failing for my case. This is the way you can reproduce it:

import numpy as np
from asciichartpy import plot
plot(np.arange(10))

The problem is only for numpy arrays, because the following is working:

import numpy as np
from asciichartpy import plot
plot(np.arange(10).tolist())

It was not failing with previous versions. Maybe is just that asciiplot doesn't support numpy arrays anymore, that's also fine, not a mayor problem.

from asciichart.

kroitor avatar kroitor commented on August 25, 2024

@ivanprado can you plz elaborate with more details (error callstack, output)?

I've tried your snippet (you have to print the result of plot) and it works on my side with 1.5.12:

mbp:asciichart igorkroitor$ python3
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from asciichartpy import plot
>>> print(plot(np.arange(10).tolist()))
    9.00  ┼        ╭
    8.00  ┤       ╭╯
    7.00  ┤      ╭╯
    6.00  ┤     ╭╯
    5.00  ┤    ╭╯
    4.00  ┤   ╭╯
    3.00  ┤  ╭╯
    2.00  ┤ ╭╯
    1.00  ┤╭╯
    0.00  ┼╯
>>>

Do you have a different result with the same lines ↑ ?

and keeps failing for my case

When you say that it's failing – can you, plz, describe how exactly it is failing by copypasting the output? Need the details, really. Thx for your involvement!

from asciichart.

kroitor avatar kroitor commented on August 25, 2024

@ivanprado ok, i've uploaded one more fix to it, please let me know if it works for you with 1.15.13:

mbp:asciichart igorkroitor$ python3
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import asciichartpy
>>> import numpy
>>> print(asciichartpy.plot(numpy.arange(10)))
    9.00  ┼        ╭
    8.00  ┤       ╭╯
    7.00  ┤      ╭╯
    6.00  ┤     ╭╯
    5.00  ┤    ╭╯
    4.00  ┤   ╭╯
    3.00  ┤  ╭╯
    2.00  ┤ ╭╯
    1.00  ┤╭╯
    0.00  ┼╯

Looking forward to hearing back from you.

from asciichart.

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.