我想把传说放在下面的每个子图中.我试过用plt.legend但它没有用.
有什么建议?
提前致谢 :-)
f, (ax1, ax2, ax3) = plt.subplots(3, sharex=True, sharey=True)
ax1.plot(xtr, color='r', label='Blue stars')
ax2.plot(ytr, color='g')
ax3.plot(ztr, color='b')
ax1.set_title('2012/09/15')
plt.legend([ax1, ax2, ax3],["HHZ 1", "HHN", "HHE"])
plt.show()
Run Code Online (Sandbox Code Playgroud)
根据atomh33ls的建议:
ax1.legend("HHZ 1",loc="upper right")
ax2.legend("HHN",loc="upper right")
ax3.legend("HHE",loc="upper right")
Run Code Online (Sandbox Code Playgroud)
图例位置是固定的,但是字符串似乎有问题,因为每个字母都放在一个新行中.
有谁知道如何解决它?
它是用以下代码生成的:
import matplotlib.pyplot as plt
import numpy as num
treshold_file='false_alarms.txt'
with open(treshold_file, 'r') as f2:
lines = f2.readlines()
data = [line.split() for line in lines]
data1 = num.array(data)
data2= data1.astype(float)
plt.hist((data2), alpha=0.4,bins=[100,110,120,130, 140,150,160,180,200,250,300,350,400])
plt.xlabel("treshold")
plt.ylabel("Frequency")
Run Code Online (Sandbox Code Playgroud)
我想为每个箱绘制大于或等于给定阈值的值的数量。
对于 bin 100,我想绘制 > 100 等的样本数。
我需要在python中设置一个环境变量,然后我尝试下面的命令
import os
basepath = os.putenv('CPATH','/Users/cat/doc')
basepath = os.getenv('CPATH','/Users/cat/doc')
Run Code Online (Sandbox Code Playgroud)
当我打印varible时,它们没有设置:print basepath None
我做错了什么?
换句话说,我想基于环境变量创建一个基本路径.我正在测试这个:
os.environ["CPATH"] = "/Users/cat/doc"
print os.environ["CPATH"]
base_path=os.getenv('C_PATH')
Run Code Online (Sandbox Code Playgroud)
当我尝试打印基道时:print basepath它总是返回None
我有一个3D数组,我希望沿XY获得一个2D图像,每个点的最大值为z,并将其保存为numpy数组.
import numpy as num
matrix=num.load('3d')
nx,ny,nz=num.shape(matrix)
CXY=num.zeros([ny, nx])
for i in range(ny):
for j in range(nx):
CXY[i,j]=num.max(matrix[j,i,:])
Run Code Online (Sandbox Code Playgroud)
问题是保存获得的矩阵.我想用numpy.save保存它,但我总是得到一个空数组.有没有人有建议正确保存获得的数组?
我刚刚使用了num.save:
num.save('max',CXY [i,j])
我想保存一个形状为(5,2)的数组,该数组名为sorted_cube_station_list.
在打印它看起来没问题,但当我用numpy.tofile保存它,然后用numpy.fromfile读取它,它就像一个1d数组
你能帮帮我吗?将numpy导入为num
nx=5
ny=5
nz=5
stations=['L001','L002','L003','L004','L005']
for x in range(nx):
for y in range (ny):
for z in range (nz):
cube_station_list = []
i=-1
for sta in stations:
i=i+1
cube=[int(i), num.random.randint(2500, size=1)[0]]
cube_station_list.append(cube)
cub_station_list_arr=num.asarray(cube_station_list)
sorted_cube_station_list_arr=cub_station_list_arr[cub_station_list_arr[:, 1].argsort()]
print x,y,z, sorted_cube_station_list_arr
num.ndarray.tofile(sorted_cube_station_list_arr,str(x)+'_'+str(y)+'_'+str(z)
Run Code Online (Sandbox Code Playgroud)