gnuplot vs Matplotlib
-
06-09-2019 - |
题
我已经开始一个项目图表 Tomcat 日志使用 gnuplot坪, ,具体相关的特定要求存分配和垃圾收集。什么是的 集体智慧gnuplot-py vs Matplotlib Python制图。是否有更好的绘图库,在那里我还没听说?
我一般考虑因素是:
- 同时gnuplot有大量的文件,gnuplot-py不。多好的文件社会Matplotlib?
- 都有东西gnuplot可以做,但gnuplot-py不能?
- 不Matplotlib有更好的蟒蛇的支持?
- 是有很大的表演停止的错误吗?烦恼?
- 目前gnuplot是绘图100,000的分,我计划在扩展这个给数以百万计。我应该期待的问题?如何Matplotlib处理这个吗?
- 易于使用、周转时间gnuplot vs Matplotlib?
- 多么容易它将港口现有的gnuplot-py码Matplotlib?
你会如何处理这个任务?
解决方案
- 你可以检查 matplotlib的文件 你自己。我发现它很全面。
- 我有很少的经验gnuplot坪,所以我不能说它是否可以做所有gnuplot。
- Matplotlib是编写和设计具体针对蟒蛇,所以它非常适合与Python语等。
- Matplotlib是一个成熟的项目。美国宇航局采用它针对一些东西。
- 我已经绘制数千万的点Matplotlib,它仍然看起来美丽和回应迅速。
- 超过面向对象的方式使用Matplotlib是pylab接口,这使得绘容易,因为它是在MATLAB-那就是,非常容易。
- 为移植从gnuplot-py到matplotlib,我不知道。
其他提示
Matplotlib=便于使用,Gnuplot=(略更好地)性能
我知道此后是旧的,并回答了但是我是路过想把我的两个美分。这里是我的结论:如果你有一个不那么大的数据集,则应使用Matplotlib.它更容易和比较好看。但是,如果你 真的 需要的性能,可以使用Gnuplot.我已经增加了一些代码,以测试它在你的机器,看看你自己如果它使得一个真正的区别(这不是一个真正的业绩基准,但应该得到第一个想法)。
以下图表所需的时间(秒):
- 阴谋的一个随机的散点图
- 保存图png文件
配置:
- gnuplot:5.2.2
- gnuplot坪:1.8
- matplotlib:2.1.2
我记得我性能差距,正在更广泛的运行时,在一个旧的计算机与旧版本的文库(-30秒差为一个大的散点图).
此外,作为mentionned在评论,可以获得同等质量的地块。但你必须把更多的汗水进到这样做有Gnuplot.
这里的代码生成的图表 如果你想给它一个尝试在您的机器:
# -*- coding: utf-8 -*-
from timeit import default_timer as timer
import matplotlib.pyplot as plt
import Gnuplot, Gnuplot.funcutils
import numpy as np
import sys
import os
def mPlotAndSave(x, y):
plt.scatter(x, y)
plt.savefig('mtmp.png')
plt.clf()
def gPlotAndSave(data, g):
g("set output 'gtmp.png'")
g.plot(data)
g("clear")
def cleanup():
try:
os.remove('gtmp.png')
except OSError:
pass
try:
os.remove('mtmp.png')
except OSError:
pass
begin = 2
end = 500000
step = 10000
numberOfPoints = range(begin, end, step)
n = len(numberOfPoints)
gnuplotTime = []
matplotlibTime = []
progressBarWidth = 30
# Init Gnuplot
g = Gnuplot.Gnuplot()
g("set terminal png size 640,480")
# Init matplotlib to avoid a peak in the beginning
plt.clf()
for idx, val in enumerate(numberOfPoints):
# Print a nice progress bar (crucial)
sys.stdout.write('\r')
progress = (idx+1)*progressBarWidth/n
bar = "▕" + "▇"*progress + "▁"*(progressBarWidth-progress) + "▏" + str(idx) + "/" + str(n-1)
sys.stdout.write(bar)
sys.stdout.flush()
# Generate random data
x = np.random.randint(sys.maxint, size=val)
y = np.random.randint(sys.maxint, size=val)
gdata = zip(x,y)
# Generate string call to a matplotlib plot and save, call it and save execution time
start = timer()
mPlotAndSave(x, y)
end = timer()
matplotlibTime.append(end - start)
# Generate string call to a gnuplot plot and save, call it and save execution time
start = timer()
gPlotAndSave(gdata, g)
end = timer()
gnuplotTime.append(end - start)
# Clean up the files
cleanup()
del g
sys.stdout.write('\n')
plt.plot(numberOfPoints, gnuplotTime, label="gnuplot")
plt.plot(numberOfPoints, matplotlibTime, label="matplotlib")
plt.legend(loc='upper right')
plt.xlabel('Number of points in the scatter graph')
plt.ylabel('Execution time (s)')
plt.savefig('execution.png')
plt.show()
后使用GNUplot(我自己的蟒蛇wrapper)长时间(与真的不喜欢上世纪80年代看出),我只是开始有一种看matplotlib.我必须说我非常喜欢它,输出看起来真的很好,医生很高的质量和广泛的(虽然这也适用于GNUplot).有一件事我花了年龄在寻找在matplotlib docs是如何写入图像的文件,而不是屏幕上!幸运的是这页说明它非常良好: http://www.dalkescientific.com/writings/diary/archive/2005/04/23/matplotlib_without_gui.html
我已经打了两个,我喜欢Matplotlib更好的条蟒蛇一体化、选项和质量图表/图。
什么Gnuplot可以做Gnuplot-Py可以做了。因为Gnuplot可以被驱动通过管道(pgnuplot).Gnuplot-Py是只有薄薄的一层。所以你不需要担心它。
为什么我更喜欢gnuplot也许许多输出格式(PDF,PS和乳胶),这是非常有用的文件,并默认输出看起来更科学的风格:)
关于业绩和绘图的大量点:我相比,这一散点图的500.000点载入文本的文件以及保存到一个png,使用gnuplot*和matplotlib.
500.000 points scatterplot
gnuplot: 5.171 s
matplotlib: 230.693 s
我运行了它,只有一次,结果看起来不完全相同,但我认为,这个想法是明确的:gnuplot赢得的业绩。
*我用gnuplot直接由于gnuplotpy演示不工作了-箱子给我。Matplotlib胜蟒蛇一体化。