Ubuntu 管理心得

搜尋此網誌

顯示具有 Python 標籤的文章。 顯示所有文章
顯示具有 Python 標籤的文章。 顯示所有文章

2025年5月15日 星期四

Graphviz dot kernel

 cf: https://github.com/laixintao/jupyter-dot-kernel

  1. chiao@kpchiao9600k-2204:~$ . .bashrc_anaconda
  2. (base) chiao@kpchiao9600k-2204:~$ pip install dot_kernel
  3. (base) chiao@kpchiao9600k-2204:~$ install-dot-kernel
  4. Done.
  5. In jupyter lab, open with dot kernel: Launcher -> Dot
  6. Edit the dot source in code cell and run.
  7. Shift right click mouse on image (Yes! need to press Shift key!). 
  8. Select "另存圖片" or "在新分頁中開啟圖片" 

Open in LibreOffice Draw:

  1. Export dot as svg, say a.svg by
    dot -Tsvg -o a.svg a.dot
  2. Insert image a.svg in draw
  3. Right click the image, and select 斷開
  4. All objects can be edited now

2024年10月20日 星期日

init_printing(use_unicode=False, wrap_line=False)

 init_printing(use_unicode=False, wrap_line=False)

2024年3月3日 星期日

Spyder 正體中文

  1. Download Chinese po file here: http://here.vixual.net/files/python/spyder/Spyder-v5.4.3-zh_TW-20231113.zip
  2. Copy add_traditional_Chinese.py (below) and Spyder-v5.4.3-zh_TW-20231113.zip to the user desktop.
  3. Run the script add_traditional_Chinese.py (Spyder or Python IDLE).
  4. Inside Spyder, Tools -> Preferences -> Application (2nd option on left panel) -> Advanced settings (right panel). Select 正體中文 in Language.
  5. Restart Spyder.

Save the following codes to add_traditional_Chinese.py:

# -*- coding: utf-8 -*-
import os
import zipfile

def unzip_and_copy(zip_file, destination):
    # Unzip the file
    with zipfile.ZipFile(zip_file, 'r') as zip_ref:
        zip_ref.extractall(destination)

def edit_base_file(base_file):
    # Read the contents of the base file
    with open(base_file, 'r', encoding='utf-8') as f:
        lines = f.readlines()

    # Find the index where to insert the new line
    insert_index = -1
    for i, line in enumerate(lines):
        if "简体中文" in line:
            insert_index = i + 1
            break

    if insert_index != -1:
        # Insert the new line
        lines.insert(insert_index, "    'zh_TW': u'正體中文',\n")

        # Write the modified content back to the file
        with open(base_file, 'w', encoding='utf-8') as f:
            f.writelines(lines)
        print("File edited successfully.")
    else:
        print("Line containing '简体中文' not found.")

if __name__ == "__main__":
    # Set paths
    desktop_path = os.path.join(os.getenv('USERPROFILE'), 'Desktop')
    zip_file = os.path.join(desktop_path, 'Spyder-v5.4.3-zh_TW-20231113.zip')
    unzip_destination = os.path.join(os.environ['USERPROFILE'], 'anaconda3', 'Lib', 'site-packages', 'spyder', 'locale')
    base_file = os.path.join(os.environ['USERPROFILE'], 'anaconda3', 'Lib', 'site-packages', 'spyder', 'config', 'base.py')

    # Step 1: Unzip and copy files
    unzip_and_copy(zip_file, unzip_destination)

    # Step 2: Edit base.py
    edit_base_file(base_file)

2023年2月3日 星期五

libGL error: MESA-LOADER: failed to open iris

 cf: https://stackoverflow.com/questions/72110384/libgl-error-mesa-loader-failed-to-open-iris

 

$ cd /home/chiao/anaconda3/lib
$ mkdir libstd_orig  # Create a new folder to keep the original libstdc++
$ mv libstd* libstd_orig  # Put all libstdc++ files into the folder, including soft links
$ cp /usr/lib/x86_64-linux-gnu/libstdc++.so.6  ./ # Copy the c++ dynamic link library of the system here
$ ln -s libstdc++.so.6 libstdc++.so
$ ln -s libstdc++.so.6 libstdc++.so.6.0.29

 

2022年6月12日 星期日

Missing figure caption

 While making pdf inside kile for book_chapterxx.tex for my /home/chiao/QuantitativeProgramming/LectureNotes/chapter11/ lecture note. The LaTeX src file exported from Jupyter cannot show the figure title.

 To fix this: comment out (put %) the 36th and 37th lines in book_chapter11.tex, e.g.

 %\DeclareCaptionFormat{nocaption}{}
 %\captionsetup{format=nocaption,aboveskip=0pt,belowskip=0pt}

The figure cation shows up now.

2022年6月8日 星期三

Add utf-8 in case of Chinese cannot be read by Python IDLE

Put the lines at the first:

#!/usr/bin/env python
# coding: utf-8

2022年5月12日 星期四

Disable Spyder help hover

Tools > Preferences > Completion and linting > Introspection

Deactivate the option: "Enable hover hints"

2022年2月17日 星期四

Matplotlib 顯示中文

 cf: https://mathsyouth.github.io/2019/06/12/macos-matplotlib

  1. Run shell command:
    fc-list :lang=zh

    to find the fonts pathes, e.g. /usr/share/fonts/truetype/bkai00mp.ttf
  2. Follow the python codes below:
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib import rcParams
    from matplotlib.font_manager import FontProperties
    rcParams['axes.unicode_minus']=False
    myfont_kai=FontProperties(fname='/usr/share/fonts/truetype/bkai00mp.ttf', size=15)
    myfont_ming=FontProperties(fname='/usr/share/fonts/truetype/arphic-bsmi00lp/bsmi00lp.ttf',size=12)
    x=np.linspace(0,2*np.pi,100)
    plt.plot(x,x)
    plt.title("準則", fontproperties=myfont_kai)
    plt.ylabel("隸屬度", fontproperties=myfont_ming)

網誌存檔