我克隆了一个由我的虚拟机上的教授创建的存储库(我正在运行Ubuntu 13.10),我们应该创建个人文件夹.我创造了我的,但我不能为我的生活提交并推动它让它出现在GitHub上.我发誓我已经尝试过这里的每一个答案,事情有所改善.例如,我最初有一个太旧的Git版本,不允许https.我还在我的个人目录中创建了一个空白文件,因为我知道GitHub不存储空文件夹.
我最初使用以下方法克隆了存储库:
$ git clone git://github.com/astrofoley/astr596.git
Run Code Online (Sandbox Code Playgroud)
然后用
git config --global user.name "myusername"
Run Code Online (Sandbox Code Playgroud)
和
git config --global user.email "myemail"
Run Code Online (Sandbox Code Playgroud)
我检查了我的教授,他确保我有足够的权限.
在这一点上,取决于我使用的提交和推送方法(我总是尝试推送到https://github.com/astrofoley/astr596.git),我得到几个不同的错误,范围从"没有添加到提交但未跟踪的文件提出"简单地"403".我不知道我做错了什么,但我怀疑它与存储库属于另一个帐户的事实有关.无论哪种方式,这都令人非常沮丧.请帮忙!
编辑:这是我当前问题的一个例子.我尝试再次使用添加和提交我的目录中的文件
git add blank.txt
Run Code Online (Sandbox Code Playgroud)
(这一步似乎运行良好)然后
git commit blank.txt
Run Code Online (Sandbox Code Playgroud)
此时我收到消息"On branch master,no nothing to commit,working directory clean".
这是我正在使用的一些代码的MWE.我通过切片和一些条件慢慢缩小初始数据帧,直到我只有我需要的行.每行五行实际上代表一个不同的对象,因此,当我减少一些事情时,如果每个五个块中的任何一行符合条件,我想保留它 - 这就是keep.index完成的循环.无论如何,当我完成时,我可以看到我想要的最终索引存在,但是我收到一条错误消息"IndexError:位置索引器超出范围".这里发生了什么?
import pandas as pd
import numpy as np
temp = np.random.rand(100,5)
df = pd.DataFrame(temp, columns=['First', 'Second', 'Third', 'Fourth', 'Fifth'])
df_cut = df.iloc[10:]
keep = df_cut.loc[(df_cut['First'] < 0.5) & (df_cut['Second'] <= 0.6)]
new_indices_to_use = []
for item in keep.index:
remainder = (item % 5)
add = np.arange(0-remainder,5-remainder,1)
inds_to_use = item + add
new_indices_to_use.append(inds_to_use)
new_indices_to_use = [ind for sublist in new_indices_to_use for ind in sublist]
final_indices_to_use = []
for item in new_indices_to_use:
if item not in final_indices_to_use:
final_indices_to_use.append(item)
final …Run Code Online (Sandbox Code Playgroud) 我发现TeX弄乱了我的字体,子图yaxis标签的对齐方式等,我觉得必须有一种更简单的方法来获取图例标签中的子脚本和上标。救命!
我有一个pandas数据框,其中包含三个对应于对象位置的x,y和z坐标的列.我还有一个转换矩阵,可以将这些点旋转一定的角度.我之前已经遍历了执行此转换的数据帧的每一行,但我发现这非常非常耗时.现在我只想一次执行转换并将结果作为附加列追加.
我正在寻找这一行的工作版本(它总是返回一个形状不匹配):
largest_haloes['X_rot', 'Y_rot', 'Z_rot'] = np.dot(rot,np.array([largest_haloes['X'], largest_haloes['Y'], largest_haloes['Z']]).T)
Run Code Online (Sandbox Code Playgroud)
这是一个最小的工作示例:
from __future__ import division
import math
import pandas as pd
import numpy as np
def unit_vector(vector):
return vector / np.linalg.norm(vector)
largest_haloes = pd.DataFrame()
largest_haloes['X'] = np.random.uniform(1,10,size=30)
largest_haloes['Y'] = np.random.uniform(1,10,size=30)
largest_haloes['Z'] = np.random.uniform(1,10,size=30)
normal = np.array([np.random.uniform(-1,1),np.random.uniform(-1,1),np.random.uniform(0,1)])
normal = unit_vector(normal)
a = normal[0]
b = normal[1]
c = normal[2]
rot = np.array([[b/math.sqrt(a**2+b**2), -1*a/math.sqrt(a**2+b**2), 0], [(a*c)/math.sqrt(a**2+b**2), b*c/math.sqrt(a**2+b**2), -1*math.sqrt(a**2+b**2)], [a, b, c]])
largest_haloes['X_rot', 'Y_rot', 'Z_rot'] = np.dot(rot,np.array([largest_haloes['X'], largest_haloes['Y'], largest_haloes['Z']]).T)
Run Code Online (Sandbox Code Playgroud)
因此,我们的目标是每行large_haloes ['X_rot','Y_rot','Z_rot']应填充相应行的largest_haloes ['X','Y','Z']的旋转版本.如何在不循环遍历行的情况下执行此操作?我也试过df.dot,但是没有太多的文档,它似乎没有做我想要的.
我正在尝试使用 math.log(1+x) 而不是通常的“log”比例选项来缩放绘图的 x 轴,并且我查看了一些自定义缩放示例,但我无法得到我的上班!这是我的 MWE:
import matplotlib.pyplot as plt
import numpy as np
import math
from matplotlib.ticker import FormatStrFormatter
from matplotlib import scale as mscale
from matplotlib import transforms as mtransforms
class CustomScale(mscale.ScaleBase):
name = 'custom'
def __init__(self, axis, **kwargs):
mscale.ScaleBase.__init__(self)
self.thresh = None #thresh
def get_transform(self):
return self.CustomTransform(self.thresh)
def set_default_locators_and_formatters(self, axis):
pass
class CustomTransform(mtransforms.Transform):
input_dims = 1
output_dims = 1
is_separable = True
def __init__(self, thresh):
mtransforms.Transform.__init__(self)
self.thresh = thresh
def transform_non_affine(self, a):
return math.log(1+a)
def inverted(self):
return …Run Code Online (Sandbox Code Playgroud) 我有一个seaborn热图,看起来像这样:
...从随机生成的值的pandas数据帧生成,其中一段看起来像这样:
沿y轴的值都在[0,1]范围内,而x轴上的值在[0,2*pi]范围内,我只需要定期为我的刻度标签设置一些短浮点数,但我似乎只能得到我的数据框中的值.当我尝试指定我想要的值时,它不会将它们放在正确的位置,如上图所示.他现在是我的代码.如何在正确的位置(沿轴均匀分布)中获取我尝试使用xticks和yticks指定的轴标签?
import pandas as pd
import numpy as np
import matplotlib as plt
from matplotlib.mlab import griddata
sns.set_style("darkgrid")
PHI, COSTH = np.meshgrid(phis, cos_thetas)
THICK = griddata(phis, cos_thetas, thicknesses, PHI, COSTH, interp='linear')
thick_df = pd.DataFrame(THICK, columns=phis, index=cos_thetas)
thick_df = thick_df.sort_index(axis=0, ascending=False)
thick_df = thick_df.sort_index(axis=1)
cmap = sns.cubehelix_palette(start=1.6, light=0.8, as_cmap=True, reverse=True)
yticks = np.array([0,0.2,0.4,0.6,0.8,1.0])
xticks = np.array([0,1,2,3,4,5,6])
g = sns.heatmap(thick_df, linewidth=0, xticklabels=xticks, yticklabels=yticks, square=True, cmap=cmap)
plt.show(g)
Run Code Online (Sandbox Code Playgroud) 我将一个平面拟合到 3d 中的一堆点,最初使用 np.meshgrid 给它一个任意大小,但现在我试图绘制一个以该平面为中心并以相同方式定向的圆柱体(这样平面拟合会切割圆柱体的高度减半),但具有指定的半径和高度。我能找到的在 matplotlib 中绘制的圆柱体的唯一示例是空心的,并且通常在顶部和底部打开。我希望我绘制的那个是实心的,这样我就可以清楚地看到它包含哪些点。
这是一个随机生成平面的最小工作示例。由于我使用的平面总是由一个点和一个法向量给出,圆柱体也应该基于这些东西(加上提供的半径和在平面上方和下方延伸的高度)。
from __future__ import division #Enables new-style division
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import seaborn as sns
import numpy as np
cen_x = 0
cen_y = 0
cen_z = 0
origin = np.array([cen_x,cen_y,cen_z])
normal = np.array([np.random.uniform(-1,1),np.random.uniform(-1,1),np.random.uniform(0,1)])
a = normal[0]
b = normal[1]
c = normal[2]
#equation for a plane is a*x+b*y+c*z+d=0 where [a,b,c] is the normal
#so calculate d from the normal
d = -origin.dot(normal)
# create x,y meshgrid
xx, …Run Code Online (Sandbox Code Playgroud)