小编tzo*_*zou的帖子

mpld3 无法正确在 x 轴上显示日期

我正在使用 matplotlib 从数据库绘制一个大型数据集,并使用 mpld3 将图形传递到浏览器。X 轴上有日期。这里的问题是,虽然在没有 mpld3 的情况下绘图工作正常,但当我使用它时,日期显示不正确。

这是我的代码:

date1 = '2015-04-22 20:28:50'
date2 = '2015-04-23 19:42:09'

db = Base('monitor').open()
result_set = db.select(['MeanVoltage','time'],"time>=start and time<=stop",  start=date1, stop=date2)

V = [float(record.MeanVoltage) for record in result_set if record != 0]
Date = [str(record.time) for record in result_set]


dates = [datetime.datetime.strptime(record, '%Y-%m-%d %H:%M:%S') for record in Date]
dates = matplotlib.dates.date2num(dates)

fig, ax = plt.subplots()
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y %H:%M:%S' ))

plt.gcf().autofmt_xdate()
ax.plot(dates,V)
#mpld3.fig_to_html(fig)
#mpld3.show(fig)
plt.show()
Run Code Online (Sandbox Code Playgroud)

完美地显示了情节,如下所示: 第一个数字

现在,如果我只注释掉这一行:

plt.show()
Run Code Online (Sandbox Code Playgroud)

并取消注释这两个:

mpld3.fig_to_html(fig)
mpld3.show(fig)
Run Code Online (Sandbox Code Playgroud)

该图在浏览器中显示如下: 第二个数字

正如您所看到的,唯一的问题是日期在 x 轴上的显示方式。有什么办法可以克服吗?

python date matplotlib axis-labels mpld3

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

使用数据表和烧瓶进行服务器端处理

我正在尝试使用 Flask 应用程序上的 sqlite 数据实现服务器端处理。我是新手,所以我无法弄清楚出了什么问题。到目前为止,我已经到了这个:

HTML :

<table id="myTable" class="table table-striped" style="width:100%" >
    <thead>  
        <tr>
            <th>Time</th>
            <th>Mean Current</th>
            <th>Vapour Pressure</th>
            <th>Mean Voltage</th>
            <th>Temperature</th>
            <th>Humidity</th>
            <th>Bar Pressure</th>
            <th>RPM</th>
            <th>Wind Sector</th>
            <th>Wind Speed</th>
            <th>Air Density</th>
            <th>DC Voltage</th>
            <th>Power Sector</th>
            <th>Furling Angle</th>
            <th>Yaw angle</th>
        </tr>
    </thead> 
</table>  
Run Code Online (Sandbox Code Playgroud)

Javascript :

$(document).ready(function() {
    $('#myTable').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "/page_test"
    } );
});
Run Code Online (Sandbox Code Playgroud)

查看功能

@app.route('/page_test')
def page_test():
    data = json.dumps(meas[2])
    print data
    return data
Run Code Online (Sandbox Code Playgroud)

meas[2] 是我的字典:

[dict((c.description[i][0], value) \
        for i, value in …
Run Code Online (Sandbox Code Playgroud)

python json datatables server-side-scripting flask

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

获取一个新数据框,熊猫中每两行的差异

我在Pandas中有一个如上所述的数据框:

    A   B   C
0   1  10  43
1   2  12  34
2   1   9  57
3   2   7  47
4   1   6  30
5   2  10  31
Run Code Online (Sandbox Code Playgroud)

我想做的是根据A列计算每两行的差异(当A = 1-A = 2时,基本上得到所有其他列的差异)。所以,我想提出这样的事情:

    B   C
0  -2   9
1   2   10
2  -4  -1
Run Code Online (Sandbox Code Playgroud)

我知道diff()函数,但似乎没有完成我想要的事情。有办法吗?

python rows dataframe pandas difference

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