Run a Python code in MATLAB 2022b
조회 수: 8 (최근 30일)
이전 댓글 표시
I have installed Pyton 3.8 and installed this library also. I wrote this code
py = py.importlib.import_module('upsetplot');
plot_handel = py.UpSet;
generate_counts=py.generate_samples;
example_counts = generate_counts()
ax_dict = plot_handel(example_counts).plot()
I am getting this error.
example_counts =
sys:1: FutureWarning: is_monotonic is deprecated and will be removed in a future version. Use is_monotonic_increasing instead.
Python Series with properties:
T: [1×1 py.pandas.core.series.Series]
array: [1×1 py.pandas.core.arrays.numpy_.PandasArray]
at: [1×1 py.pandas.core.indexing._AtIndexer]
attrs: [1×1 py.dict]
axes: [1×1 py.list]
dtype: [1×1 py.numpy.dtype[int64]]
dtypes: [1×1 py.numpy.dtype[int64]]
empty: 0
flags: [1×1 py.pandas.core.flags.Flags]
hasnans: 0
iat: [1×1 py.pandas.core.indexing._iAtIndexer]
iloc: [1×1 py.pandas.core.indexing._iLocIndexer]
index: [1×1 py.pandas.core.indexes.multi.MultiIndex]
is_monotonic: 0
is_monotonic_decreasing: 0
is_monotonic_increasing: 0
is_unique: 1
loc: [1×1 py.pandas.core.indexing._LocIndexer]
name: [1×5 py.str]
nbytes: [1×1 py.int]
ndim: [1×1 py.int]
shape: [1×1 py.tuple]
size: [1×1 py.int]
values: [1×1 py.numpy.ndarray]
cat0 cat1 cat2
False False False 56
True 283
True False 1279
True 5882
True False False 24
True 90
True False 429
True 1957
Name: value, dtype: int64
Error using __init__
Python Error: IndexError: list index out of range
Error in _backend_tk>create_with_canvas (line 457)
Error in backend_bases>new_manager (line 1703)
Error in backend_bases>new_figure_manager_given_figure (line 3518)
Error in backend_bases>new_figure_manager (line 3513)
Error in pyplot>new_figure_manager (line 359)
Error in pyplot>figure (line 783)
Error in deprecation>wrapper (line 454)
Error in plotting>plot (line 842)
I tested the code given on the link in Python and it worked. However its not woring in MATLAB. How can I resolve it?
The website says that output example_counts is a pandas.Series with 3-level Multi-index. Does MATALB is changing this thats why its not able to plot?
Thank You.
댓글 수: 0
답변 (1개)
Rushikesh
2024년 9월 19일
Hello @Masood Salik
The "IndexError" you are facing while using the 'plot' function of the "upsetplot.UpSet" Python library is likely related to the Tcl/Tk library, which is often used by the 'matplotlib' library for rendering plots when using the TkAgg backend. This issue typically arises when the Python environment is unable to locate the Tcl/Tk installation required for the TkAgg backend.
To resolve this, try specifying the TCL_LIBRARY and TK_LIBRARY environment variables to point to the correct directories in the MATLAB Command Window.
For example, you can use the code given below:
setenv('TCL_LIBRARY', 'C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\tcl\tcl8.6');
setenv('TK_LIBRARY', 'C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\tcl\tk8.6');
Using MATLAB 2022b and Python 3.8, I attempted to replicate the error you encountered. By setting the specified environment variables, I successfully resolved the issue and generated the desired plot. Please find the attached screenshot of the output for your reference.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!