import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
fig = plt.figure(figsize=(11.69,8.27), dpi=100)
bottom, top = 0.1, 0.9
left, right = 0.1, 0.8
fig.subplots_adjust(top=top, bottom=bottom, left=left, right=right, hspace=0.15, wspace=0.25)
for num in range(12):
ax = fig.add_subplot(3,4,num+1)
im = ax.scatter(np.random.rand(10), np.random.rand(10), 12, np.random.rand(10), cmap='magma')
fig.text(0.5, 0.02, 'x label', ha='center', fontsize=16)
fig.text(0.02, 0.5, 'ylabel ', va='center', rotation='vertical', fontsize=16)
cbar_ax = fig.add_axes([0.85, bottom, 0.05, top-bottom])
fig.colorbar(im, cax=cbar_ax)
fig.savefig("example.pdf", dpi=fig.dpi, pad_inches=0.3)
它给了我所有数据,但我只需要3个随机数据。我有Google会随机获得N个数据,但为什么不为我工作?
答案 0 :(得分:0)
function get() {
return new Promise(function (resolve, reject) {
Card.aggregate([
{ $sample: {size: Number(req.body.wordCount)} },
{ $match: {"deckId": new mongoose.Types.ObjectId(req.body.deckId)} }
]).exec(function(err,result){
if(err){
reject(err);
}else{
resolve(result)
}
});
});
}