在Python中使用数据框和此代码,我能够创建一个图:
g = sns.lmplot('credibility', 'percentWatched', data=data, hue = 'millennial', markers = ["+", "."], x_jitter = True, y_jitter = True, size=5)
g.set(xlabel = 'Credibility Ranking\n ? Low High ?', ylabel = 'Percent of Video Watched [%]')
Run Code Online (Sandbox Code Playgroud)
但是有传说说"+ 0"和".1"对读者来说并不是很有帮助.如何编辑图例的标签?理想情况下,它不是说"千禧一代",而是说"一代"和"+千禧一代"."老一代"
在我的一个程序中,我怀疑我是否正确使用了比较.我想在做某事之前确保(u0 <= u <u0 +步骤).
if not (u0 <= u) and (u < u0+step):
u0 = u0+ step # change the condition until it is satisfied
else:
do something. # condition is satisfied
Run Code Online (Sandbox Code Playgroud) 我如何计算任何给定物体的旋转角度(即uiimageview)?
我编写了下面的函数,将下划线转换为camelcase,第一个单词为小写,即"get_this_value" - >"getThisValue".此外,我还要求保留前导和尾随下划线以及双重(三重等)下划线,如果有的话,即
"_get__this_value_" -> "_get_ThisValue_".
Run Code Online (Sandbox Code Playgroud)
代码:
def underscore_to_camelcase(value):
output = ""
first_word_passed = False
for word in value.split("_"):
if not word:
output += "_"
continue
if first_word_passed:
output += word.capitalize()
else:
output += word.lower()
first_word_passed = True
return output
Run Code Online (Sandbox Code Playgroud)
我感觉上面的代码是用非Pythonic风格编写的,虽然它按预期工作,所以看看如何简化代码并使用列表推导等编写代码.
假设我运行以下脚本:
import matplotlib.pyplot as plt
lineWidth = 20
plt.figure()
plt.plot([0,0],[-1,1], lw=lineWidth, c='b')
plt.plot([-1,1],[-1,1], lw=lineWidth, c='r')
plt.plot([-1,1],[1,-1], lw=lineWidth, c='g')
plt.show()
Run Code Online (Sandbox Code Playgroud)
这产生以下结果:
如何指定图层的从上到下的顺序,而不是让我选择Python?
是否有使用matplotlib在图形/图形下面绘制标题框的功能?我搜索谷歌并没有找到任何这样的功能.
像图像中显示的东西会很棒.
在以下python代码中:
narg=len(sys.argv)
print "@length arg= ", narg
if narg == 1:
print "@Usage: input_filename nelements nintervals"
break
Run Code Online (Sandbox Code Playgroud)
我明白了:
SyntaxError: 'break' outside loop
Run Code Online (Sandbox Code Playgroud)
为什么?
使用Python,我如何将字段提取id
到变量?基本上,我改变这个:
{
"accountWide": true,
"criteria": [
{
"description": "some description",
"id": 7553,
"max": 1,
"orderIndex": 0
}
]
}
Run Code Online (Sandbox Code Playgroud)
喜欢的东西
print "Description is: " + description
print "ID is: " + id
print "Max value is : " + max
Run Code Online (Sandbox Code Playgroud) 我想修复多个散点图上的颜色范围,并在每个图中添加一个颜色条(每个图中都是相同的).基本上,我正在修复轴和颜色空间等的所有方面,以便绘图直接可以通过眼睛进行比较.
对于我的生活,我似乎无法弄清楚修复颜色范围的各种方法.我已经尝试了vmin,vmax,但它似乎没有做任何事情,我也试过攀登(x,y),这似乎也没有用.
这必须在这里和那里出现,我不能是唯一一个想要比较各个数据子集的人...所以,你如何修复颜色,以便每个数据保持它的颜色之间的颜色和不由于子集的最大/最小值的变化-v-整个集合,会重新映射到不同的颜色?
我正在使用matplotlib绘制对数标准化的图像,但我希望原始的原始图像数据在颜色条中表示而不是[0-1]区间.通过使用某种规范化对象并且不事先转换数据,我感觉有更多的matplotlib'y方法.在任何情况下,原始图像中都可能存在负值.
import matplotlib.pyplot as plt
import numpy as np
def log_transform(im):
'''returns log(image) scaled to the interval [0,1]'''
try:
(min, max) = (im[im > 0].min(), im.max())
if (max > min) and (max > 0):
return (np.log(im.clip(min, max)) - np.log(min)) / (np.log(max) - np.log(min))
except:
pass
return im
a = np.ones((100,100))
for i in range(100): a[i] = i
f = plt.figure()
ax = f.add_subplot(111)
res = ax.imshow(log_transform(a))
# the colorbar drawn shows [0-1], but I want to see [0-99]
cb = …
Run Code Online (Sandbox Code Playgroud) python ×9
matplotlib ×5
cocoa-touch ×1
colors ×1
ios ×1
layer ×1
legend ×1
normalize ×1
plot ×1
scatter-plot ×1
seaborn ×1