- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试生成由一些硬编码字符串组成的 word_cloud 的 svg(截至目前,稍后将动态生成这些字符串)。下面是生成word_cloud的Python代码:
from os import path
from wordcloud import WordCloud
d = path.dirname(__file__)
# Read the whole text.
#text = open(path.join(d, 'test.txt')).read()
mytext = ['hello, hi, ibm, pune, hola']
# Generate a word cloud image
wordcloud = WordCloud().generate(text)
import svgwrite
# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
现在我不想使用 plt.show(),而是想将 wordcloud 变量传递给 svgwrite 方法,如下所示:
svg_document = svgwrite.Drawing(filename = "test-svgwrite.svg",profile = 'full')
svg_document.add(svg_document.text(wordcloud,
insert = (210, 110)))
svg_document.tostring()
svg_document.save()
但是,这个创建的 SVG 不包含任何文字云,只包含文本(如下图所示): check the screenshot here
最佳答案
面对使用 matplotlib 的一些问题(虽然它会保存为“.svg”,但它会结合 wordcloud 使用光栅图形),我想出了另一种方法
wordcloud = WordCloud()
wordcloud.generate_from_frequencies(frequencies=features)
wordcloud_svg = wordcloud.to_svg(embed_font=True)
f = open("filename.svg","w+")
f.write(wordcloud_svg )
f.close()
embed_font bool 值防止单词重叠。您还可以自由修改 wordcloud_svg 以更改颜色、字体等。它具有类似 xml 的结构(打印出来 :))
关于python - 如何将 python wordcloud 元素传递给 svgwrite 方法以生成 wordcloud 的 svg?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44715044/
我正在尝试更正以下代码: import svgwrite dwg = svgwrite.Drawing('test.svg', profile='tiny') dwg.add(dwg.circle((
我在我的 Python 代码中使用 svgwrite 模块,我想设置背景颜色。到目前为止,我还没有找到任何东西。有办法吗? 我希望在初始化过程中得到一些东西: import svgwrite canv
我在 python 中使用 svgwrite 根据我的 Tensorflow 模型生成输出以输出模拟手写文本。我当前的设置需要一个字符串数组来表示换行符,但是生成的文本大小不一致,有时会在行中的最后一
我正在使用 SVGWRITE 库创建生物信息学工具。 我需要一些使用 animate 模块的帮助(例如 animateColor、animateMotion...),因为即使我阅读了文档,也阅读了 s
我正在尝试制作一个连接到网络抓取工具的 SVG 文件。 如何使用 svgwrite 更改字体和文本大小?我知道我必须定义一个 CSS 样式并以某种方式将其连接到文本对象。但这是如何制作的? 这是我目前
我想提取文本对象的像素大小 (svgwrite.Drawing.Text),因为它在使用给定样式格式化后会出现在文件中。我的字体是固定宽度的(Courier New)。 我需要它的原因是我想将一个字符
有没有人有在 svgwrite (python) 中完成的弧形切片(奶酪切片或吃 bean 人)的工作示例,我已经尝试过这个,试图获得一个从 (100,100) 开始的西北象限,但得到一个奇怪的形状:
我有一个 svg 文件,我想在现有文件中插入其他 svg 对象。 import svgwrite dwg = svgwrite.Drawing('model.svg') square = dwg.ad
我正在使用 python 的 svgwrite 生成 SVG 绘图。每次我想画点东西的时候,我发现自己在做这种丑陋而尴尬的事情: line = drawing.line(start = "%dmm"
我需要导入一张已有的svg图片,并在上面添加圆、方等元素。我的文件是“test.svg”,所以我尝试了 dwg = svgwrite.Drawing('test.svg') 但它创建了一个没有任何内容
使用折线实体使用 svgwrite-1.1.9 构建 svg 文件。 如何防止输出翻转?坐标似乎困惑了 - 垂直 (y) 被翻转。 这是我用来生成折线的代码: # generate svg eleme
我正在使用 python 及其模块 svgwrite 创建一个 svg 文件。除了圆圈等(效果很好)之外,我还需要输入另一个 svg 文件。为此,我使用了: dwg = svgwrite.Drawin
我正在尝试构建一个具有线条特征的 SVG,每条线条都会链接到同一文档中其他位置的部分。我不断收到 ValueError但是,指出“Invalid children 'line' for svg-ele
有没有人有关于如何使用 svgwrite 将 SVG 过滤器应用于 SVG 组的示例? 这是我正在尝试做的事情: import svgwrite dwg = svgwrite.Drawing('tes
我正在使用 svgwrite模块以编程方式为项目创建一些图像。我需要使用 alpha 蒙版来创建渐变透明元素。我不清楚创建蒙版后如何应用蒙版。 在下面的示例中,我尝试使用圆形渐变在原本为灰色的正方形中
我正在尝试生成由一些硬编码字符串组成的 word_cloud 的 svg(截至目前,稍后将动态生成这些字符串)。下面是生成word_cloud的Python代码: from os import pat
我在将 TextPath 元素与 svgwrite 库一起使用时遇到问题。我遵循文档 https://pythonhosted.org/svgwrite/classes/text.html#textp
我是一名优秀的程序员,十分优秀!