简体   繁体   English

如何在 Latex pygal 标签中渲染

[英]How to render in Latex pygal labels

I have some 2d data points that come with labels that I would like to render in pygal.我有一些带有标签的二维数据点,我想在 pygal 中呈现它们。 For example say that for each point I need to visualise a feature when I over on it with the mouse.例如,对于每个点,当我用鼠标经过它时,我需要可视化一个特征。

First of all, to plot the points without any labels, I did the following:首先,为了绘制没有任何标签的点,我执行了以下操作:

import pygal                                                       # 

data = [(0, 0), (.1, .2), (.3, .1), (.5, 1), (.8, .6), (1, 1.08), (1.3, 1.1), (2, 3.23), (2.43, 2)]

xy_chart = pygal.XY(stroke=False)
xy_chart.title = 'Correlation'
xy_chart.add('A', data)
xy_chart.render()

And it plots all the data as I wish, without labels (meaning that if I over with the mouse on a point, it gives me only the class 'A' and the coordinates of the point).它按照我的意愿绘制了所有数据,没有标签(这意味着如果我将鼠标放在一个点上,它只会给我“A”类和该点的坐标)。

Now, In order to add labels to my data, how should I modify the code?现在,为了给我的数据添加标签,我应该如何修改代码? Initially, I tried to do this:最初,我尝试这样做:

xy_chart.add('A', [{'value': data, 'label': r'$\tau = 2.3'}])

But it gives me error unsupported operand type(s) for -: 'tuple' and 'tuple但它给了我错误unsupported operand type(s) for -: 'tuple' and 'tuple

If I consider only one element of the list per time, like:如果我每次只考虑列表中的一个元素,例如:

first_elem = data[0]
xy_chart.add('A', [{'value': first_elem, 'label': r'$\tau = 2.3'}])

it works without errors, but it does not render in latex the labels, so I see in the image $\\tau = 2.3$ instead of the rendered latex code.它工作没有错误,但它不会在乳胶中呈现标签,所以我在图像中看到$\\tau = 2.3$而不是呈现的乳胶代码。

So two problems: the first one is how can I put labels on points in general and the second one is how do I render those labels in Latex所以有两个问题:第一个是我如何在点上放置标签,第二个是我如何在 Latex 中渲染这些标签

Regarding your second question: I'm not sure pygal supports LaTeX (I wasn't able to find any information about this — correct me if I'm wrong).关于您的第二个问题:我不确定 pygal 是否支持 LaTeX(我无法找到有关此的任何信息 - 如果我错了,请纠正我)。

Regarding your first question: populate your data list with dictionaries as follows:关于你的第一个问题:用字典填充你的数据列表,如下所示:

data = [{'value': (0, 0), 'label': "τ = 2.3"},
        (.1, .2), (.3, .1), (.5, 1), (.8, .6), (1, 1.08), (1.3, 1.1),
        (2, 3.23), (2.43, 2)]
...
xy_chart.add('A', data)
...

(I only showed it for the first term of your list). (我只在你列表的第一学期展示了它)。

By the way, you're able to include some unicode characters so, unless you want labels with involved mathematical formulas, you should be able to get some symbols (like τ here).顺便说一下,您可以包含一些 unicode 字符,因此,除非您想要包含数学公式的标签,否则您应该能够获得一些符号(如这里的τ )。

You can use list comprehensions to programmatically determine your labels.您可以使用列表推导以编程方式确定您的标签。 Eg,例如,

data = [(0, 0), (.1, .2), (.3, .1), (.5, 1), (.8, .6), (1, 1.08), (1.3, 1.1), (2, 3.23), (2.43, 2)]
labelled_data = [{'value': k, 'label': "τ = 2.3"} for k in data]
...
xy_chart.add('A', labelled_data)
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM