Skip to content

Commit

Permalink
feat: add font_path arg for wordcloud (#1598)
Browse files Browse the repository at this point in the history
using font_path argument in Wordcloud, if we don't use a font in Wordcloud, multi-language be broken

Adjust lint for commit

Co-authored-by: JoDongHyun <dong.jo@navercorp.com>
  • Loading branch information
DongHyun-JO and JoDongHyun authored Jun 17, 2024
1 parent 9946037 commit 0e8fedd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/ydata_profiling/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class Plot(BaseModel):
histogram: Histogram = Histogram()
scatter_threshold: int = 1000
cat_freq: CatFrequencyPlot = CatFrequencyPlot()
font_path: Optional[Union[Path, str]] = None


class Theme(Enum):
Expand Down
2 changes: 2 additions & 0 deletions src/ydata_profiling/config_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ plot:
# Maximum number of bins (when bins=0)
max_bins: 250

font_path: null

# The number of observations to show
n_obs_unique: 5
n_extreme_obs: 5
Expand Down
2 changes: 2 additions & 0 deletions src/ydata_profiling/config_minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ plot:
# Maximum number of bins (when bins=0)
max_bins: 250

font_path: null

# The number of observations to show
n_obs_unique: 5
n_extreme_obs: 5
Expand Down
10 changes: 8 additions & 2 deletions src/ydata_profiling/visualisation/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def format_fn(tick_val: int, tick_pos: Any) -> str:


def _plot_word_cloud(
config: Settings,
series: Union[pd.Series, List[pd.Series]],
figsize: tuple = (6, 4),
) -> plt.Figure:
Expand All @@ -36,7 +37,12 @@ def _plot_word_cloud(
for i, series_data in enumerate(series):
word_dict = series_data.to_dict()
wordcloud = WordCloud(
background_color="white", random_state=123, width=300, height=200, scale=2
font_path=config.plot.font_path,
background_color="white",
random_state=123,
width=300,
height=200,
scale=2,
).generate_from_frequencies(word_dict)

ax = plot.add_subplot(1, len(series), i + 1)
Expand Down Expand Up @@ -124,7 +130,7 @@ def _plot_histogram(

@manage_matplotlib_context()
def plot_word_cloud(config: Settings, word_counts: pd.Series) -> str:
_plot_word_cloud(series=word_counts)
_plot_word_cloud(config=config, series=word_counts)
return plot_360_n0sc0pe(config)


Expand Down

0 comments on commit 0e8fedd

Please sign in to comment.