Last active
          August 7, 2018 11:17 
        
      - 
      
- 
        Save tai271828/f044456a39734c178456e46e5c71bc6f to your computer and use it in GitHub Desktop. 
    List available system and matplotlib fonts to see which font is available to matplotlib
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/env python3 | |
| from matplotlib.font_manager import FontManager | |
| import subprocess | |
| fm = FontManager() | |
| mat_fonts = set(f.name for f in fm.ttflist) | |
| output = subprocess.check_output( | |
| 'fc-list :lang=zh -f "%{family}\n"', shell=True) | |
| output = output.decode('utf-8') | |
| zh_fonts = set(f.split(',', 1)[0] for f in output.split('\n')) | |
| available = mat_fonts & zh_fonts | |
| print('*' * 10, '系統中的字體', '*' * 10) | |
| print(zh_fonts) | |
| print('*' * 10, 'matplotlib 讀到的字體', '*' * 10) | |
| print(mat_fonts) | |
| print('*' * 10, '可用的字體 - 系統中和 matplotlib 讀到的字體交集', '*' * 10) | |
| for f in available: | |
| print(f) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment