小编cjd*_*jds的帖子

matplotlib 中无效的 rgba arg“#”

我无法弄清楚在尝试在 matplotlib 中创建散点图时如何使用颜色。

我正在尝试绘制具有不同颜色点的多个散点图来显示集群。

colors=['#12efff','#eee111','#eee00f','#e00fff','#123456','#abc222','#000000','#123fff','#1eff1f','#2edf4f','#2eaf9f','#22222f'
        '#eeeff1','#eee112','#00ef00','#aa0000','#0000aa','#000999','#32efff','#23ef68','#2e3f56','#7eef1f','#eeef11']
C=1
fig = plt.figure()
ax = fig.gca(projection='3d')
for fgroups in groups:
   X=[np.random.rand(50),np.random.rand(50),np.random.rand(50)]
   y=[np.random.rand(50),np.random.rand(50),np.random.rand(50)]
   Z=[np.random.rand(50),np.random.rand(50),np.random.rand(50)]
   C=(C+1) % len(colors)
   ax.scatter(X,Y,Z, s=20, c=colors[C], depthshade=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)

我收到的错误如下:

ValueError: to_rgba: 无效的 rgba arg "#" to_rgb: 无效的 rgb arg "#" 无法将字符串转换为浮点数: #

看起来它将这些 RGB 参数视为浮点数。

然而,在 matplotlib 文档中,颜色是以这种风格编写的http://matplotlib.org/api/colors_api.html

我缺少什么?

python matplotlib scatter-plot

5
推荐指数
1
解决办法
1万
查看次数

如何调整图像大小以适应DIV jQuery

我有方形DIV和大型肖像和风景图像.

我需要在DIV中将图像与额外部分相匹配 overflow:hidden

例如.如果纵向设置宽度= div高度的宽度:auto

与Lanscape相反.

我试过这个脚本,但它没有用

        $('.magic').each(function(){
        if($(this).css('width')>$(this).css('height')){
            $(this).css('height', '300px');
            $(this).css('width', 'auto');                
        }
        else{
            $(this).css('width', '300px');
            $(this).css('height', 'auto');


        }
    });
Run Code Online (Sandbox Code Playgroud)

PS图像无法拉伸,必须缩放

html jquery web

3
推荐指数
1
解决办法
8871
查看次数

list.map没有显示在React Component中

我试图在视图中获取此列表,但这不显示任何项目

render: function() {
    var list = this.state.list;
    console.log('Re-rendered');
    return(
        <ul>
        {list.map(function(object, i){
            <li key='{i}'>{object}</li>
        })}
        </ul>
    )
}
Run Code Online (Sandbox Code Playgroud)

list首先设置为null,然后我用AJAX重新加载它.另一方面,这是有效的

    <ul>
    {list.map(setting => (
        <li>{setting}</li>
    ))}
    </ul>
Run Code Online (Sandbox Code Playgroud)

这是我的整个组件:

var Setting = React.createClass({
   getInitialState: function(){
     return {
       'list': []
     }
   },
   getData: function(){
     var that = this;
     var myHeaders = new Headers();
     var myInit = { method: 'GET',
           headers: myHeaders,
           mode: 'cors',
           cache: 'default' };
    fetch('/list/',myInit)
        .then(function(response){
            var contentType = response.headers.get("content-type");
            if(contentType && contentType.indexOf("application/json") !== -1) {
            return response.json().then(function(json) { …
Run Code Online (Sandbox Code Playgroud)

reactjs

3
推荐指数
1
解决办法
1013
查看次数

使用dep init时不在任何GOPATH中

我正在尝试使用godep安装我的依赖项,但我似乎无法让它工作.当我运行GODEP init时,我收到以下错误

determineProjectRoot:/ home/cjds/development/core/data-service不在任何$ GOPATH中

但是我的GOPATH肯定包含了这条道路.这是我走的全路

/家庭/ cjds /开发/核心/数据服务

go install 导致以下错误,这可能是问题的根源:

/ home/cjds/development/core/data-service中没有可构建的Go源文件

然而,文件夹结构有一个src文件夹,然后是一个main文件夹,然后是我的整个Go项目

- /主页/ cjds /开发/核心/数据业务/ src目录/主/我-GO-files.go

go godeps

3
推荐指数
1
解决办法
6875
查看次数

django 测试的覆盖设置似乎不起作用

我必须在 Django 的测试中覆盖设置

@override_settings(XYZ_REDIRECT="http://localhost:8000")
@override_settings(TOKEN_TIMEOUT=0)
class CustomTestCase(TestCase):

    def setUp(self):
        self.token = self._generate_auth_token()
        self.client = Client()

    def test_token_expiry(self):
        feoken_count = 0
        client = Client()
        client.post('/api/v1/auth/login/', {'token': 'AF'})
        # Over HERE TOKEN_TIMEOUT is not changed
        self.assertEqual(ABCN.objects.count(), feoken_count)
Run Code Online (Sandbox Code Playgroud)

然而,覆盖设置装饰器似乎不起作用。在路线的另一边,我有这个代码。

from fetchcore_server.settings import AUTH0_SERVER_URL, TOKEN_TIMEOUT
....
def post(self, request, *args, **kwargs):
    if 'token' in request.data:
        FetchcoreToken.objects.filter(expiry_time__lte=timezone.now()).delete()
        print TOKEN_TIMEOUT # this is still original value
        token = request.data['token']
        try:
            fetchcore_token = FetchcoreToken.objects.get(token=token)
            user = fetchcore_token.user
            user_id = user.id
Run Code Online (Sandbox Code Playgroud)

我尝试使用with self.settings(TOKEN_TIMEOUT=0)但即使这样也不起作用。

我不确定我是如何使用这个错误的

关于该主题的 Django …

python django

3
推荐指数
1
解决办法
2822
查看次数

为什么在 Python 中没有提示 self 类型

我一直在研究类型提示我的代码,但注意到 Python 程序员通常不会self在他们的程序中键入提示

即使我查看文档,它们似乎也没有输入提示 self,请参见 此处。这是来自 3.10 版的前向声明

    def __init__(self, value: T, name: str, logger: Logger) -> None:
Run Code Online (Sandbox Code Playgroud)

我可以理解为什么在 3.7 中引入带有前向声明的类型注释之前,这是一个问题

更多信息 在这里这里


这对我来说似乎有用的原因是 mypy 似乎能够捕捉到这个问题的错误

例子:

from __future__ import annotations

class Simple(object):
    def __init__(self: Simple):
        print(self.x)
          
Run Code Online (Sandbox Code Playgroud)

将从 mypy 返回这个

mypy test.py 
test.py:5: error: "Simple" has no attribute "x"
Found 1 error in 1 file (checked 1 source file)
Run Code Online (Sandbox Code Playgroud)

如果您从中删除类型,则self变为

Success: no issues found in 1 source file

Run Code Online (Sandbox Code Playgroud)
  • 是否有self未注释的原因,或者这是唯一的约定?
  • 是否有我遗漏的权衡或者我的注释self …

python mypy

3
推荐指数
1
解决办法
129
查看次数

通过代码加载视图控制器

我有几个ViewControllers的故事板,通过按钮相互连接.

现在,如果特定条件为真,我需要加载另一个UIViewController.我设法创建了一个新的子类,但我想避免它.我只是想

if(condition == true){
  // load viewcontroller located in the storyboard, not connected with anything else
}
Run Code Online (Sandbox Code Playgroud)

有帮助吗?

xcode controller view objective-c viewcontroller

2
推荐指数
1
解决办法
2361
查看次数

Python Maxent分类器

我一直在python中使用maxent分类器,它失败了,我不明白为什么.

我正在使用电影评论语料库.(总菜鸟)

import nltk.classify.util
from nltk.classify import MaxentClassifier
from nltk.corpus import movie_reviews

def word_feats(words):
 return dict([(word, True) for word in words])

negids = movie_reviews.fileids('neg')
posids = movie_reviews.fileids('pos')

negfeats = [(word_feats(movie_reviews.words(fileids=[f])), 'neg') for f in negids]
posfeats = [(word_feats(movie_reviews.words(fileids=[f])), 'pos') for f in posids]

negcutoff = len(negfeats)*3/4
poscutoff = len(posfeats)*3/4

trainfeats = negfeats[:negcutoff] + posfeats[:poscutoff]
classifier = MaxentClassifier.train(trainfeats)
Run Code Online (Sandbox Code Playgroud)

这是错误(我知道我做错了,请链接到Maxent如何工作)

警告(来自警告模块):文件"C:\ Python27\lib\site-packages \nltk\classify\maxent.py",第1334行sum1 = numpy.sum(exp_nf_delta*A,axis = 0)运行时警告:遇到无效值乘以

警告(来自警告模块):文件"C:\ Python27\lib\site-packages \nltk\classify\maxent.py",第1335行sum2 = numpy.sum(nf_exp_nf_delta*A,axis = 0)运行时警告:遇到无效值乘以

警告(来自警告模块):文件"C:\ Python27\lib\site-packages \nltk\classify\maxent.py",第1341行deltas - =(ffreq_empirical - sum1)/ -sum2 …

python nltk maxent

2
推荐指数
1
解决办法
8838
查看次数

Android 构建工具可以始终保持最新吗(而不是指定版本)

好的,假设您有一个应用程序,它是使用构建工具版本 21 构建的。现在,版本 24 已经发布。您的应用运行良好。但是,您的应用程序在构建时可能没有对构建工具进行优化和更改。

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
...
Run Code Online (Sandbox Code Playgroud)

我的问题是,有没有办法直接设置buildToolsVersion为最新版本。

您是否应该随着时间的推移更新构建工具。它有什么区别吗?


只是,要清楚,我并不是要征求意见。更多什么是处理构建工具更新时的标准模型。我应该等到我需要新版本的东西还是继续更新以进行优化

android build-tools

2
推荐指数
1
解决办法
341
查看次数

Docker中主机操作系统的lsb_release

我想获得我在Docker中运行的操作系统.

这就是我的docker-compose样子,我将继承python:2.7图像

 version: '2'
 services:
   robot-configuration-interface:
     build: '.'
     restart: always
     network_mode: 'host'
     ports:
       - 8000:80
     environment:
       - REDIS_HOST=localhost
       - DEBUG=true
     volumes:
       - ~/logs/fetchcore-server:/var/log/supervisor
       - /var/run/docker.sock:/var/run/docker.sock
       - /opt/ros/indigo:/opt/ros/indigo
       - /etc/environment:/etc/environment
       - /etc/NetworkManager/system-connections/:/etc/NetworkManager/system-connections/
       - /lib:/lib
       - /usr/lib/:/usr/lib
       - /usr/bin/:/usr/bin/
       - /var/run/:/var/run/
     privileged: true
     user: root
Run Code Online (Sandbox Code Playgroud)

lsb_release -d命令返回Debian GNU/Linux 8.7(n/a)而不是Ubuntu 14.04.5 LTS,即使我正在安装/usr/bin

ubuntu docker docker-compose

2
推荐指数
1
解决办法
4501
查看次数