小编ash*_*ana的帖子

Plotly中用于条形图的单独标记条形图

我试图为分组条形图创建注释 - 其中每个条形图都有一个特定的数据标签,显示该条形图的值并位于条形图的中心上方.

我尝试对教程中的示例进行简单修改以实现此目的,如下所示:

import plotly.plotly as py
import plotly.graph_objs as go

x = ['Product A', 'Product B', 'Product C']
y1 = [20, 14, 23]
y2 = [12, 18, 29]

annotations1 = [dict(
            x=xi,
            y=yi,
            text=str(yi),
            xanchor='auto',
            yanchor='bottom',
            showarrow=False,
        ) for xi, yi in zip(x, y1)]
annotations2 = [dict(
            x=xi,
            y=yi,
            text=str(yi),
            xanchor='auto',
            yanchor='bottom',
            showarrow=False,
        ) for xi, yi in zip(x, y2)]
annotations = annotations1 + annotations2

trace1 = go.Bar(
    x=x,
    y=y1,
    name='SF Zoo'
)
trace2 = go.Bar(
    x=x,
    y=y2, …
Run Code Online (Sandbox Code Playgroud)

python r bar-chart plotly

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

Node.JS请求的rejectUnauthorized为false

我正在尝试使用request用于Node.js 的模块来制定HTTPS GET请求。使用该https模块的相应代码如下:

var https = require('https');

var options = {
    hostname: url,
    path: path,
    rejectUnauthorized: false,
    secureProtocol: 'TLSv1_method',
    port: 8443,
    method: 'POST'
  };

https.get(options, function(response) {
    var body = ''; 
    response.on('data', function(chunk) {
        body += chunk.toString();
    });
    response.on('end', function() {
        var content = JSON.parse(body);
        console.log(content);
    });
});
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下request模块重写此代码:

var request = require('request');

var options = {
    url: url,
    strictSSL: false
}

request.get(options, function(error, response, body) {
    if (error) {
        console.log(error);
    } else { …
Run Code Online (Sandbox Code Playgroud)

request node.js

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

Python Programming: Multiline Comments before an Else statement

I was working with simple if-else statements in Python when a syntax error came up with the following code.

"""
A multi-line comment in Python
"""
if a==b:
    print "Hello World!"

"""
Another multi-line comment in Python
"""
else:
    print "Good Morning!"
Run Code Online (Sandbox Code Playgroud)

This code gives a syntax error at the "else" keyword.

The following code however does not:

"""
A multi-line comment in Python
"""
if a==b:
    print "Hello World!"

#One single line comment
#Another single line comment
else:
    print …
Run Code Online (Sandbox Code Playgroud)

python comments if-statement

4
推荐指数
1
解决办法
1826
查看次数

标签 统计

python ×2

bar-chart ×1

comments ×1

if-statement ×1

node.js ×1

plotly ×1

r ×1

request ×1