我最近决定尝试使用matplotlib.pyplot,同时使用gnuplot进行科学数据绘图多年.我开始时只需读取一个数据文件并绘制两列,就像gnuplot那样plot 'datafile' u 1:2.我的舒适要求是:
#并跳过空行.现在,以下代码是我解决问题的方法.然而,与gnuplot相比,它确实没那么快.这有点奇怪,因为我读到py(plot/thon)相对于gnuplot的一大优势是它的速度.
import numpy as np
import matplotlib.pyplot as plt
import sys
datafile = sys.argv[1]
data = []
for line in open(datafile,'r'):
if line and line[0] != '#':
cols = filter(lambda x: x!='',line.split(' '))
for index,col in enumerate(cols):
if len(data) <= index:
data.append([])
data[index].append(float(col))
plt.plot(data[0],data[1])
plt.show()
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能让数据读取更快?我快速浏览了一下这个csv模块,但是文件中的注释似乎并不灵活,而且还需要迭代文件中的所有行.
我正在尝试使用带有makefile的GNUplot生成一些图形.我希望目录中的每个*.plt文件都可以通过GNUplot运行,但是我看不到让它工作.到目前为止,这是我的makefile:
all: %.tex
%.tex: %.plt
<tab> gnuplot < $<
Run Code Online (Sandbox Code Playgroud)
如果我单独指定一个.plt文件,配方工作正常,但我希望它在我生成它们时拾取我的新图.
编辑:我想我现在已经开始工作了:
# plots all files in the folder with .plt extensions
SOURCES = $(wildcard *.plt)
TARGETS = $(SOURCES:.plt=.tex)
all: $(TARGETS)
%.tex: %.plt
gnuplot < $<
Run Code Online (Sandbox Code Playgroud)
有人可以确认我的推理(如下)是否正确?以前我没有指定任何文件all(我有点困惑%).现在SOURCES通过使用通配符拾取任何.plt文件来分配变量(为什么在使用.plt而不是*.plt?时它不起作用).分配后SOURCE,设置TARGETS变量,现在all:指定要构建的文件.现在运行匹配规则.
我正在使用命令在gnuplot中制作调色板:
set pm3d implicit at b
set palette model RGB maxcolors 5
set cbrange [0:20]
set palette model RGB defined (4 '#006400', 8 '#00008B', 12 'blue', 16 '#C71585', 20 'red')
set cbtics 4
Run Code Online (Sandbox Code Playgroud)
这样我在垂直调色板上从上到下得到订单20,16,12,8,4,0.我需要从上到下阅读0,4,8,12,16,20.
我没有找到任何已经存在此订单的示例(从最小到最大).
谢谢你的建议:)
嗨,我正在尝试使用gnuplot-iostream,此时我只是想让代码在这里工作.当我尝试组合时,我在链接器中遇到错误:
In function `stream<int, boost::iostreams::file_descriptor_flags>':
/usr/include/boost/iostreams/stream.hpp:130: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(int, boost::iostreams::file_descriptor_flags)'
In function `boost::iostreams::file_descriptor_sink boost::iostreams::detail::wrap<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink const&, boost::disable_if<boost::iostreams::is_std_io<boost::iostreams::file_descriptor_sink>, void>::type*)':
/usr/include/boost/iostreams/detail/wrap_unwrap.hpp:53: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
In function `concept_adapter':
/usr/include/boost/iostreams/detail/adapter/concept_adapter.hpp:67: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
/usr/include/boost/iostreams/detail/adapter/concept_adapter.hpp:38: undefined reference to `boost::iostreams::file_descriptor_sink::file_descriptor_sink(boost::iostreams::file_descriptor_sink const&)'
In function `long boost::iostreams::detail::write_device_impl<boost::iostreams::output>::write<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, boost::iostreams::char_type_of<boost::iostreams::file_descriptor_sink>::type const*, long)':
/usr/include/boost/iostreams/write.hpp:121: undefined reference to `boost::iostreams::file_descriptor::write(char const*, long)'
In function `void boost::iostreams::detail::close_impl<boost::iostreams::closable_tag>::close<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, std::_Ios_Openmode)':
/usr/include/boost/iostreams/close.hpp:224: undefined reference to `boost::iostreams::file_descriptor::close()'
In function `std::fpos<__mbstate_t> boost::iostreams::detail::seek_device_impl<boost::iostreams::any_tag>::seek<boost::iostreams::file_descriptor_sink>(boost::iostreams::file_descriptor_sink&, long, std::_Ios_Seekdir, std::_Ios_Openmode)':
/usr/include/boost/iostreams/seek.hpp:137: undefined reference to `boost::iostreams::file_descriptor::seek(long, std::_Ios_Seekdir)'
collect2: ld …Run Code Online (Sandbox Code Playgroud) 可能重复:
如何在Gnuplot中缩放轴
我有x和y轴有大数字(1000,2000等)但是我希望重新编写或重新缩放它们而不更改或重新缩放数据,这样1000轴在轴上是1,等等.我不寻找1x10 ^ 3.让1000成为1.我有什么方法可以做到这一点?
我想通过绘制x轴采样时间点和磁盘上使用的y轴存储来显示磁盘上已用空间的变化情况.但是,目前,使用的存储器以字节为单位记录,当值超过GB时,这不是人类可读的.
那么,我可以在gnuplot中重新调整轴吗?在我的情况下,我可以将值更改100000000为100MB?
谢谢和最诚挚的问候.
我有几个数据文件顺序命名为'1.dat','2.dat'...,'100.dat'.我想为Gnuplot中的每个数据文件创建一个png(或任何其他类型)图像.我的终极主题是从这样生成的图像中创建一部电影,但我发现这些令人困惑的软件包,并且更愿意一步一步地完成.如何编写用于从数据文件中创建图像的脚本?谢谢.
我有一个使用MPI的C++程序,我希望每个进程(最多32个)写入文件.我正在使用一个小的测试数据集,其中包含100个双重均匀分布在整个过程中的数据集.到目前为止,输出的格式如下:
data_sink.Write(&d_p[i], 1, MPI::DOUBLE);
data_sink.Write(&space, 1, MPI::CHAR);
data_sink.Write(&r_p[j], 1, MPI::DOUBLE);
data_sink.Write(&new_line, 1, MPI::CHAR);
Run Code Online (Sandbox Code Playgroud)
格式化此输出的最佳方法是什么,以便GNUPlot可以直接解释结果?
我很难在我的3d图上将y轴和z轴标签与轴tics对齐.这是我的代码.
set ylabel "Infectious Duration (days)" rotate by 90
set zlabel "Compute Time (sec)" rotate by 90
set logscale x
splot "TCompISIS3d.txt" using 1:2:3 title 'SIS-Inf1' with points , \
"TCompISIS3d.txt" using 1:4:5 title 'SIS-Inf4' with points , \
"TCompISIS3d.txt" using 1:6:7 title 'SIS-Inf10' with points , \
"TCompISIS3d.txt" using 1:8:9 title 'SIS-Inf50' with points
Run Code Online (Sandbox Code Playgroud)
但它不会旋转任何标签.请帮忙!
我已经看过很多关于在gnu情节中绘制数据的教程,但是我还没有找到我应该在哪里放置我的数据集文件进行绘图.在许多教程中都有一个像"plot'example.dat'"这样的命令,但这个example.dat文件确实放在哪里?