我正在尝试将gnuplot与OSX 10.8.2一起使用,并且看到x11是一个ambiguous or unknown terminal type
.一些研究显示x11
不受支持,我下载XQartz
,但我仍然得到相同的错误消息.
我编辑.bash_profile,export GNUTERM = 'x11'
然后ln -sf /Application/Utilities/XQuartz.app/ X11.app
按照此处的建议进行尝试
但仍然是相同的错误消息.我还可以尝试绘制我的gnuplot
文件(在我的笔记本电脑和服务器上)?
谢谢.
我正在 ipython 笔记本中创建一个带有一些文本的图形(例如:一边有一些文本的 sin 曲线)。绘图和文本显示在我的笔记本中,但是当我保存图形时,我只能看到绘图而不是文本。我用这个示例代码重现了这个问题:
import numpy as np
import matplotlib.pyplot as plt
fig,ax = plt.subplots(1)
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
ax.plot(x, y)
ax.text(8,0.9,'Some Text Here',multialignment='left', linespacing=2.)
plt.savefig('sin.pdf')
Run Code Online (Sandbox Code Playgroud)
如何查看保存的pdf中的文本?
是否可以使用创建的日期和时间来命名我的 gnuplot out 文件?我目前创建的文件的名称设置如下:
set term post eps color
set output '/path/dateandtime.eps'
plot
set term x11
Run Code Online (Sandbox Code Playgroud) 在使用 numpy.savetxt 时,是否有内置的错误处理来防止覆盖文件?如果 'my_file' 已经存在,我运行
numpy.savetxt("my_file", my_array)
我希望生成一个错误,告诉我文件已经存在,或者询问用户是否确定要写入文件。
按照这个例子,我可以创建一个简单的数据框和groupby
import pandas as pd
# Create a sample data frame
df = pd.DataFrame({'A': ['foo', 'foo', 'foo', 'bar', 'bar'],
'B': range(5), 'C': range(5)})
# group by 'A' and sum 'B'
gf = df.groupby('A').agg({'B': 'sum'})
Run Code Online (Sandbox Code Playgroud)
结果是分组数据框 gf
B
A
bar 7
foo 3
Run Code Online (Sandbox Code Playgroud)
我想通过分组索引访问 gf 。就像是...
gf['foo'] returns 3
gf['bar'] returns 7
Run Code Online (Sandbox Code Playgroud)
我还想按分组索引进行绘图。就像是...
gf.plot('A', 'B') such that x=['foo','bar'], y=[3,7]
Run Code Online (Sandbox Code Playgroud) 在文本文件中有这一行
initial_mass = unknown_int
Run Code Online (Sandbox Code Playgroud)
我想换行
initial_mass = known_int
Run Code Online (Sandbox Code Playgroud)
顾名思义,我不会知道初始值,但我想用已知值替换它.使用Python,我如何搜索以'initial_mass'开头的行,然后用'initial_mass = known_int'替换整行?
我正在思考
import fileinput
for line in fileinput.FileInput(filename, inplace=True):
line=line.replace(old, new)
print(line),
Run Code Online (Sandbox Code Playgroud)
如何设置old
包含的行initial_mass = uknown_int
?我看过startswith()
但我不知道怎么用它来得到我想要的东西.我也试过正则表达式,发现它完全令人困惑.
该文件不是特别大,但我需要多次迭代这个过程.
我有一个2D数组,在这里我试图绘制一列中所有行的直方图,给定另一列中的条件.我试图在plt.hist()命令中选择子数据,以避免产生许多子数组,我已经知道如何做.例如,如果
a_long_named_array = [1, 5]
[2, 6]
[3, 7]
Run Code Online (Sandbox Code Playgroud)
我可以通过写入创建我的数组的子集,使第1列大于5
a_long_named_subarray = a_long_named_array[a_long_named_array[:,1] > 5]
Run Code Online (Sandbox Code Playgroud)
如何在不制作上述子阵列的情况下绘制此子数据?请看下面.
import numpy as np
import matplotlib.pyplot as plt
#Generate 2D array
arr = np.array([np.random.random_integers(0,10, 10), np.arange(0,10)])
#Transpose it
arr = arr.T
#----------------------------------------------------------------------------
#Plotting a Histogram: This works
#----------------------------------------------------------------------------
#Plot all the rows of the 0'th column
plt.hist(arr[:,0])
plt.show()
#----------------------------------------------------------------------------
#Plotting a conditional Histogram: This is what I am trying to do. This Doesn't work.
#----------------------------------------------------------------------------
#Plot all the rows of the 0th column where …
Run Code Online (Sandbox Code Playgroud) 我将一个整数设置为小于其最大值的值,但是收到的错误是它太大了.为什么是这样?这是一个示例程序.
program max_int
integer, parameter :: i32 = selected_int_kind(32)
integer(kind = i32) :: my_int
!The largest integer of this kind
print*, huge(my_int)
!This works
my_int = 100000
!This doesn't, and gives an error.
!my_int = 1000000000000
print*, my_int
end program
Run Code Online (Sandbox Code Playgroud) 我想使用带有2个四核处理器的Mac Pro并行化以下python循环.
result_list = []
for a in a_range:
for b in b_range:
for c in c_range:
result = call_fortran_program(a, b, c)
result_list.append(result)
Run Code Online (Sandbox Code Playgroud)
在我的搜索中,我遇到了像Cython和GIL这样的术语,但我仍然不清楚如何继续.
python ×5
gnuplot ×2
matplotlib ×2
numpy ×2
fortran ×1
osx-lion ×1
pandas ×1
python-3.x ×1
x11 ×1