我正在使用python(在LinuxMint中使用虚拟环境),我安装了pygal.
一切正常(渲染到html)但不渲染到svg或png.结果:只有黑色背景.
我安装cssselect并tinycss喜欢这里提到的.
它是第一次工作,但在重试时,我遇到了同样的问题.
(我不知道这是否相关,但在上周使用黑暗表格导出照片时,这种情况发生在我身上)
我使用pygal网站上的例子:
import pygal # First import pygal
bar_chart = pygal.Bar() # Then create a bar graph object
bar_chart.add('Fibonacci', [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]) # Add some values
bar_chart.render_to_file('bar_chart.svg') # Save the svg to a file
Run Code Online (Sandbox Code Playgroud)
编辑:
bar_chart.render_to_png('bar_chart.png')
Run Code Online (Sandbox Code Playgroud)
现在正在工作.
但不是:
bar_chart.render_to_file('bar_chart.svg')
Run Code Online (Sandbox Code Playgroud) 我试着
from pygal.i18 import COUNTRIES
Run Code Online (Sandbox Code Playgroud)
但我得到的只是
ImportError: No module named 'pygal.i18n'.
Run Code Online (Sandbox Code Playgroud)
谁能告诉我这是什么问题?
谢谢
我正在尝试使用两个测量来绘制多个系列(所以它实际上是使用pygal在一个图中的num_of_个时间序列*2个图.数据看起来应该是这样的:
from collections import defaultdict
measurement_1=defaultdict(None,[
("component1", [11.83, 11.35, 0.55]),
("component2", [2.19, 2.42, 0.96]),
("component3", [1.98, 2.17, 0.17])])
measurement_2=defaultdict(None,[
("component1", [34940.57, 35260.41, 370.45]),
("component2", [1360.67, 1369.58, 2.69]),
("component3", [13355.60, 14790.81, 55.63])])
x_labels=['2016-12-01', '2016-12-02', '2016-12-03']
Run Code Online (Sandbox Code Playgroud)
图形呈现代码是:
from pygal import graph
import pygal
def draw(measurement_1, measurement_2 ,x_labels):
graph = pygal.Line()
graph.x_labels = x_labels
for key, value in measurement_1.iteritems():
graph.add(key, value)
for key, value in measurement_2.iteritems():
graph.add(key, value, secondary=True)
return graph.render_data_uri()
Run Code Online (Sandbox Code Playgroud)
当前结果是那.
上面代码中的问题是,不清楚哪个图表属于测量1,哪个图表属于测量2.其次,我希望在两个测量中看到颜色(或形状)中的每个成分(现在看起来像他们根本没有关系.例如component1 -pink,component2-green,component3-yellow
该图旨在比较一个组件与另外两个组件,并查看测量1和2之间的相关性.
我希望我很清楚.
谢谢你的帮助!
是否可以使用折线系列和条形系列创建单个图表?
chart = pygal.Line()
chart.x_labels = 'Red', 'Blue', 'Green'
chart.y_labels = .0001, .0003, .0004, .00045, .0005
chart.add('line', [.0002, .0005, .00035])
Run Code Online (Sandbox Code Playgroud) pygal,呈现svg并返回图表字典.我尝试将其嵌入到web2py页面中.这样可行.但我无法弄清楚如何减少页面上图形的大小.
风景:
{{extend 'layout.html'}}
<h1>Hello {{=request.vars.simulation_id}}</h1>
<figure>
{{=XML(one)}}
{{=XML(two)}}
</figure>
Run Code Online (Sandbox Code Playgroud)
和default.py函数:
def run_simulation():
simulation = start.Simulation()
graphs = simulation.run()
return graphs
Run Code Online (Sandbox Code Playgroud) 我想放入类似于matplotlib中提供的以下内容的axspan,以便在图形中有一条垂直线指出一个位置。这是使用pygal的折线图
plt.axvspan(fin_loc, fin_loc+1, color='red', alpha=0.5)
我使用 pyGal 制作图表,但我无法将它们插入到 django 模板中。如果我在 views.py 中尝试这样,效果很好
return HttpResponse(chart.render())
Run Code Online (Sandbox Code Playgroud)
但是当我在我的模板中制作这样的东西时根本不起作用
{{chart.render}}
Run Code Online (Sandbox Code Playgroud) 我有一个 MDS 投影结果的元组 (x,y) 列表,我需要显示点名称/标签。所以我还有一个标签列表。
例如:
labels = ['a','b','c','d']
points = [(1,2),(1,3),(1,4),(4,5)]
xy_chart = pygal.XY(stroke=False,style=LightColorizedStyle)
xy_chart.title = 'MDS projection'
xy_chart.add('Result', points)
Run Code Online (Sandbox Code Playgroud)
我看到了一个使用元数据和字典进行条形图的解决方案:
chart = pygal.Bar()
chart.add('Red', [{
'value': 2,
'label': 'This is red',
'xlink': 'http://en.wikipedia.org/wiki/Red'}])
chart.add('Green', [{
'value': 4,
'label': 'This is green',
'xlink': 'http://en.wikipedia.org/wiki/Green'}])
Run Code Online (Sandbox Code Playgroud)
我如何使用 Pygal 中的散点图 XY 函数来做到这一点?
我想在 python 2.7 上使用 Pygal 创建一个仪表板(同一窗口中的几个图),但后者没有 subplot 功能,是否有解决方案,不使用散景或绘图?
Matplotlib 上的示例:
fig, axes = plt.subplots(ncols=4, nrows=5, figsize=(35,20))
for ax in axes.flatten():
ax.plot([2,3,5,1])
plt.show()
Run Code Online (Sandbox Code Playgroud)
Pygal 上有类似的东西吗?
我目前使用 Jupyter Notebooks,我想通过 HTML 呈现 SVG,而不将它们保存为本地 SVG 并在之后显示它们。
我使用此代码:
%matplotlib inline
from IPython.display import SVG, HTML
html_pygal = """
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/svg.jquery.js"></script>
<script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/pygal-tooltips.js"></script>
<!-- ... -->
</head>
<body>
<figure>
{pygal_render}
</figure>
</body>
</html>
"""
import pygal
line_chart = pygal.Line()
line_chart.title = 'Browser usage evolution (in %)'
line_chart.x_labels = map(str, range(2002, 2013))
line_chart.add('Firefox', [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1])
line_chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, …Run Code Online (Sandbox Code Playgroud) pygal ×10
python ×6
svg ×2
anaconda ×1
charts ×1
continuum ×1
data-science ×1
django ×1
import ×1
javascript ×1
jupyter ×1
matplotlib ×1
python-2.7 ×1
rendering ×1
web2py ×1