Coder Social home page Coder Social logo

Comments (8)

domvwt avatar domvwt commented on May 22, 2024 1

What if we replace the text with this 📊?

This is on line 7 of https://github.com/domvwt/esparto/blob/main/esparto/resources/jinja/base.html.jinja.

from esparto.

apwebber avatar apwebber commented on May 22, 2024 1

Yes that works :)

from esparto.

domvwt avatar domvwt commented on May 22, 2024

Thanks for reporting this. I've tried to reproduce on my machine but I was able to run the following code successfully:

import matplotlib.pyplot as plt

import esparto


def test_no_negative_char():

    fig, ax = plt.subplots()
    x = [1,2,3,4,5]
    y = [1,0.5, 0, 1, 2]
    ax.plot(x, y)

    page = esparto.Page(title="Test")
    page["Plot"] = fig
    page.save_html("test-fig-01.html")

def test_negative_char():
    """This fails

    UnicodeEncodeError: 'charmap' codec can't encode character '\u2212' in position 13531: character maps to <undefined>
    """

    fig, ax = plt.subplots()
    x = [1,2,3,4,5]
    y = [-1,-0.5, 0, 1, 2]
    ax.plot(x, y)

    page = esparto.Page(title="Test")
    page["Plot"] = fig
    page.save_html("test-fig-02.html")

if __name__ == "__main__":
    test_no_negative_char()
    test_negative_char()

This makes me think it's a Windows OS specific issue as I've been developing and testing in a Linux environment.

Could you share the full error message so I can pinpoint where the error is occurring?

from esparto.

domvwt avatar domvwt commented on May 22, 2024

One other thing, could you try setting the figure format to PNG as an interim solution?

from esparto import options

options.matplotlib.notebook_format = "png"
options.matplotlib.html_output_format = "png"

from esparto.

apwebber avatar apwebber commented on May 22, 2024

Hi domvwt

I have a fix that works on my machine.

In esparto/publish/output.py, line 69

    if filepath:
        Path(filepath).write_text(html_rendered)

Specifying the encoding fixes this for me:

    if filepath:
        Path(filepath).write_text(html_rendered, encoding='utf-8')

This is the full error message I was getting:

File "C:\Users\*\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "C:\Users\*\Envs\lab-progress-env\lib\site-packages\esparto\design\layout.py", line 482, in save_html
    html = publish_html(
  File "C:\Users\*\Envs\lab-progress-env\lib\site-packages\esparto\publish\output.py", line 70, in publish_html
    Path(filepath).write_text(html_rendered)
  File "C:\Users\*\AppData\Local\Programs\Python\Python39\lib\pathlib.py", line 1286, in write_text
    return f.write(data)
  File "C:\Users\*\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2212' in position 13531: character maps to <undefined>

from esparto.

apwebber avatar apwebber commented on May 22, 2024

Although a funny side effect of the above fix is that the page icon is now random letters:

<link href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>Γ°ΕΈβ€œΕ </text></svg>" rel="icon">

from esparto.

domvwt avatar domvwt commented on May 22, 2024

Great, thanks for making the fix!

If you can make a pull request with your changes I'll merge and make a new release.

from esparto.

domvwt avatar domvwt commented on May 22, 2024

I've made a develop branch that you can use as the base - I think you'll need to fork the repository first if you haven't already.

from esparto.

Related Issues (6)

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.