Code Monkey home page Code Monkey logo

Comments (6)

chanshunli avatar chanshunli commented on July 19, 2024 1

@cnuernber , My project is here: https://github.com/chanshunli/matplotlib-clj :-D

from libpython-clj.

cnuernber avatar cnuernber commented on July 19, 2024

Hmm. I don't think this is fixable from the outside. Probably you will need to use the canvas renderers for matplotlib or only use it from the main thread, not a repl thread (which would be a shame).

Good idea for a project though.

from libpython-clj.

chanshunli avatar chanshunli commented on July 19, 2024

I run this plot in lein run ,not other thread :

坚持去λ化(eshell) matplotlib-clj  master $ lein run
十一月 16, 2019 12:20:10 上午 clojure.tools.logging$eval486$fn__489 invoke
信息: executing python initialize!
十一月 16, 2019 12:20:10 上午 clojure.tools.logging$eval486$fn__489 invoke
信息: Library /usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib found at [:system "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib"]
十一月 16, 2019 12:20:10 上午 clojure.tools.logging$eval486$fn__489 invoke
信息: Reference thread starting
2019-11-16 00:20:11.618 java[997:1376858] WARNING: NSWindow drag regions should only be invalidated on the Main Thread! This will throw an exception in the future. Called from (
	0   AppKit                              0x00007fff2c69e6ef -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 371
	1   AppKit                              0x00007fff2c69bbc1 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1416
	2   AppKit                              0x00007fff2c69b633 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42
	3   _macosx.cpython-37m-darwin.so       0x000000012ca016b0 -[Window initWithContentRect:styleMask:backing:defer:withManager:] + 80
	4   _macosx.cpython-37m-darwin.so       0x000000012ca04bc7 FigureManager_init + 327
	5   Python                              0x0000000124647050 wrap_init + 12
	6   Python                              0x000000012460e407 wrapperdescr_call + 337
	7   Python                              0x0000000124608668 _PyObject_FastCallKeywords + 365
	8   Python                              0x000000012469f3ad call_function + 746
	9   Python                              0x0000000124697f6f _PyEval_EvalFrameDefault + 7020
	10  Python                              0x0000000124608bdd function_code_fastcall + 112
	11  Python                              0x0000000124609561 _PyObject_Call_Prepend + 150
	12  Python                              0x0000000124646fbe slot_tp_init + 80
	13  Python                              0x0000000124643c85 type_call + 178
	14  Python                              0x0000000124608668 _PyObject_FastCallKeywords + 365
	15  Python                              0x000000012469f3ad call_function + 746
	16  Python                              0x0000000124697f6f _PyEval_EvalFrameDefault + 7020
	17  Python                              0x0000000124608bdd function_code_fastcall + 112
	18  Python                              0x000000012469f3b4 call_function + 753
	19  Python                              0x0000000124697f6f _PyEval_EvalFrameDefault + 7020
	20  Python                              0x000000012469fc5c _PyEval_EvalCodeWithName + 1857
	21  Python                              0x000000012460842a _PyFunction_FastCallDict + 441
	22  Python                              0x0000000124609561 _PyObject_Call_Prepend + 150
	23  Python                              0x0000000124608910 PyObject_Call + 136
	24  Python                              0x0000000124698286 _PyEval_EvalFrameDefault + 7811
	25  Python                              0x000000012469fc5c _PyEval_EvalCodeWithName + 1857
	26  Python                              0x00000001246087c7 _PyFunction_FastCallKeywords + 225
	27  Python                              0x000000012469f3b4 call_function + 753
	28  Python                              0x000000012469800d _PyEval_EvalFrameDefault + 7178
	29  Python                              0x0000000124608bdd function_code_fastcall + 112
	30  Python                              0x000000012469f3b4 call_function + 753
	31  Python                              0x000000012469800d _PyEval_EvalFrameDefault + 7178
	32  Python                              0x000000012469fc5c _PyEval_EvalCodeWithName + 1857
	33  Python                              0x00000001246087c7 _PyFunction_FastCallKeywords + 225
	34  Python                              0x000000012469f3b4 call_function + 753
	35  Python                              0x000000012469800d _PyEval_EvalFrameDefault + 7178
	36  Python                              0x000000012469fc5c _PyEval_EvalCodeWithName + 1857
	37  Python                              0x000000012460842a _PyFunction_FastCallDict + 441
	38  jna2383965882915598410.tmp          0x000000010d842e74 ffi_call_unix64 + 76
	39  ???                                 0x000070000ee0e578 0x0 + 123145551930744
)

The Code is here :

(ns matplotlib-clj.core
  (:require [libpython-clj.python :as py]
            [tech.v2.datatype :as dtype]
            [tech.libs.buffered-image :as bufimg]
            [tech.v2.tensor :as dtt]
            [clojure.java.io :as io]
            [clojure.java.shell :as sh]))

(defn init-macox []
  (alter-var-root
   #'libpython-clj.jna.base/*python-library*
   (constantly "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib"))
  (py/initialize!))

(init-macox)

(def mfig (py/import-module "matplotlib.figure"))
(def magg (py/import-module "matplotlib.backends.backend_agg"))
(def np (py/import-module "numpy"))
(def plt (py/import-module "matplotlib.pyplot"))

(def x (py/call-attr np "linspace" 0 2 100))
;;(py/python-type x)
;;(py/get-attr x "shape")

(defn plot-it []
  (py/call-attr-kw plt "plot" [x x] {"label" "linear"})
  (py/call-attr-kw plt "plot" [x (py/call-attr x "__pow__" 2)] {"label" "quadratic"})
  (py/call-attr-kw plt "plot" [x (py/call-attr x "__pow__" 3)] {"label" "cubic"})
  (py/call-attr plt "xlabel" "x label")
  (py/call-attr plt "ylabel" "y label")
  (py/call-attr plt "title" "Simple Plot")
  (py/call-attr plt "legend"))

(defn -main [& args]
  (plot-it)
  (py/call-attr plt "show"))

from libpython-clj.

cnuernber avatar cnuernber commented on July 19, 2024

I found a matplotlib issue related to this:

matplotlib/matplotlib#14304

from libpython-clj.

chanshunli avatar chanshunli commented on July 19, 2024

Thanks @cnuernber, I use the WebAgg, it's work :-D

(def mplot (py/import-module "matplotlib"))
(py/call-attr mplot "use" "WebAgg")

截屏2019-11-16上午12 55 15

from libpython-clj.

cnuernber avatar cnuernber commented on July 19, 2024

Nice work!!

Closing as I believe this is a matplotlib issue and not a libpython-clj issue.

from libpython-clj.

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.