- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想创建一个词云。当我的字符串是英文时,一切正常:
from wordcloud import WordCloud
from matplotlib import pyplot as plt
text="""Softrock 40 - close to the 6 MHz that the P6D requires (6.062 according) - https://groups.yahoo.com/neo/groups/softrock40/conversations/messages
I want the USB model that has a controllable (not fixed) central frequency."""
wordcloud = WordCloud().generate(text)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
但是当我用希伯来语做同样的事情时,它没有检测到字体,我只得到空的矩形:
text="""תחילתו של חורף מאכזב למדיי, מומחי המים בישראל מאמינים כי לראשונה השנה מפלס הכנרת יעלה בצורה משמעותית מגשמי הסערה שתחל היום"""
wordcloud = WordCloud().generate(text)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
有什么想法吗?
最佳答案
这与 wordcloud 本身没有太大关系,但更多与渲染有关:您使用(默认情况下是)一种根本不包含任何希伯来字符“定义”的字体。因此,它只是简单地呈现矩形。
但是我们可以使用支持希伯来字符的字体,例如 FreeSansBold。我们可以通过 WordCloud
构造函数传递字体路径:
from wordcloud import WordCloud
from matplotlib import pyplot as plt
text="""תחילתו של חורף מאכזב למדיי, מומחי המים בישראל מאמינים כי לראשונה השנה מפלס הכנרת יעלה בצורה משמעותית מגשמי הסערה שתחל היום"""
wordcloud = WordCloud(<b>font_path='/usr/share/fonts/truetype/freefont/FreeSansBold.ttf'</b>).generate(text)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
然后这会生成以下词云:
我对希伯来语不是很熟悉,但我的印象是这些词是从左到右书写的,而不是从右到左书写的。无论如何,如果这是一个问题,我们可以使用 python-bidi
首先处理语言的方向,例如:
from wordcloud import WordCloud
from matplotlib import pyplot as plt
from bidi.algorithm import get_display
text="""תחילתו של חורף מאכזב למדיי, מומחי המים בישראל מאמינים כי לראשונה השנה מפלס הכנרת יעלה בצורה משמעותית מגשמי הסערה שתחל היום"""
bidi_text = <b>get_display(text)</b>
wordcloud = WordCloud(font_path='/usr/share/fonts/truetype/freefont/FreeSansBold.ttf').generate(bidi_text)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show()
对于给定的文本,我们得到如下图像:
关于python - 在 python 中为外语(希伯来语)创建 wordcloud,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54063438/
我正在尝试生成由一些硬编码字符串组成的 word_cloud 的 svg(截至目前,稍后将动态生成这些字符串)。下面是生成word_cloud的Python代码: from os import pat
我正在尝试从数据框中创建词云,其中有一列单词和一列代表它们各自的频率。我还下载了一张我想用作 mask 的图像,例如:cloud image 我无法让 wordcloud 适合 mask - 尽管遵循
我正在使用 twitter API 来产生情绪。我正在尝试根据推文生成词云。 这是我生成 wordcloud 的代码 wordcloud(clean.tweets, random.order=F,ma
我正在使用 Jupyter Notebook 并尝试构建词云。事实证明,枕头包装存在一些问题,互联网上充满了围绕它的讨论。我最初收到 DLL 错误。我尝试了很多不同的方法,不确定哪一种有效,但现在,我
我是 python 的新手,我正在使用 wordcloud pkg。 我根据字典 frequencies 中的频率生成了一个词云,key=words 和 values=frequencies of t
在词云中我有重复的词,我不明白为什么它们不一起计算,然后显示为一个词。 from wordcloud import WordCloud word_string = 'oh oh oh oh oh oh
在绘制词云图时发现有的字颜色为黄色导致看不清因此需要修改整个词云图的色调为冷色调 具体的来说 wordcloud中的color_func 参数使得我们能够自定义颜色函数
使用 wordcloud 时,我正在努力传播这些词功能。 data = tibble(Day = c("January", "February", "March" , "April", "May",
这似乎是一个简单的问题,但我似乎无法在任何地方找到答案。在 R {wordcloud} 包的 wordcloud 函数中,有一个可以输入的比例值。完整的文档(此处: https://cran.r-pr
我想用 R 构建一个词云(我已经使用 wordcloud 包做到了这一点),然后将特定单词涂上某种颜色。目前该函数的行为是根据频率给单词着色(这可能很有用),但单词大小已经做到了这一点,所以我想使用颜
我正在 python 中使用 wordcloud 库处理词云。 举个例子,我想从以下列表中制作一个词云: word_ls = ['orchards growers northern', 'apple
我正在创建一个词云,其中词的大小基于频率,但我希望将词的颜色映射到第三个变量(压力,这是与每个词相关的压力量,数值或连续变量)。 我尝试了以下方法,它只给了我两种不同的颜色(黄色和紫色),而我想要
我有以下 WordCloud。原始代码来自 Jason Davies D3-JavaScript-WordCloud Example。 https://github.com/jasondavies/d
我正在尝试以一种方式制作几个词云的子图/方面 赏心悦目。 问题: 我无法让基础 R 组合 wordcloud - 正确输出 使用 ggplot2 制作 wordcloud允许刻面但产生不令人满意的结果
我正在尝试在我的 GWT 项目中使用 d3-wordcloud( https://github.com/jasondavies/d3-cloud )。我将其包含在我的 .html 文件中: 其
我有以下功能作为 Shiny 应用程序(testapp)的一部分。它会生成默认选择的词云,但不会使用新选择进行更新。 ui.R library(shiny) shinyUI(fluidPage(
使用来自的描述功能 Online retail dataset , 我创建了一个词云。 descCorpus % rename(word=description, freq=sales) %>% wo
我正在尝试在此链接中制作有关电影类型的词云,但出现一些错误,名称“wordcloud”未定义即使包wordcloud 已安装。 有人可以帮我吗,python的版本是3.6.3。 import nump
我正在尝试使用这个 library 在 React 容器内创建一个词云.当通过数组 test 时,wordcloud 工作。 我想调用一个 api 来获取 wordcloud 的单词,然后将其传递给
我想突出显示用户点击的每个术语/单词,并为该特定术语/单词设置一个背景框。我正在使用点击功能,我可以访问和设置单词本身的颜色,但我无法设置这个单词的背景。我怎样才能做到这一点? 这是我的绘制函数: f
我是一名优秀的程序员,十分优秀!