Skip to content

Commit de39b06

Browse files
[fix] : fix consolas font error in linux, load tty file
1 parent 679e911 commit de39b06

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

paperplotlib/consola-1.ttf

94.5 KB
Binary file not shown.

paperplotlib/graph.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# 非交互式 GUI 使用 Agg
33
matplotlib.use('Agg')
44
import matplotlib.pyplot as plt
5+
import os
56
from typing import List, Optional, Union, Tuple
6-
7+
from matplotlib.font_manager import FontProperties
8+
import matplotlib.font_manager as fm
79

810
class Graph:
911
"""
@@ -33,7 +35,14 @@ def __init__(self, style_id: int = 1) -> None:
3335
self.bbox_inches = "tight" # 适当上下左右留白
3436

3537
self.title: Optional[str] = None # 图表标题
36-
self.font_family = "Consolas" # 字体
38+
39+
font_path = f'{os.path.dirname(__file__)}/consola-1.ttf'
40+
fm.fontManager.addfont(font_path)
41+
plt.rcParams['font.family'] = 'Consolas'
42+
# self.font_family = "Consolas" # 字体
43+
# 如果是 linux
44+
# if os.name == 'posix':
45+
# self.font_family = consolas_font.get_name()
3746
# self.colors: Optional[List[str]] = None
3847

3948
def plot(self, x_data: List[float], y_data: List[float]): # pragma: no cover
@@ -55,10 +64,7 @@ def plot_2d(self, y_data: List[List[float]], group_names: List[str], column_name
5564

5665
def _create_graph(self): # pragma: no cover
5766
self._check_config()
58-
59-
# set font
60-
plt.rcParams["font.family"] = self.font_family
61-
67+
6268
if self.width_picture:
6369
self.fig.set_size_inches(16, 4)
6470
self.ax.set_xlabel(self.x_label)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "paperplotlib"
3-
version = "0.0.5"
3+
version = "0.0.7"
44
description = "论文实验数据绘图"
55
authors = ["luzhixing12345 <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)