我正在尝试将数据从csv文件转换为热图.目前,我的热图如下所示:

但它错过了一个传奇!这是我的代码:
import matplotlib.pyplot as plt
import numpy as np
column_labels = list(range(0,24))
row_labels = ["Lundi",
"Mardi",
"Mercredi",
"Jeudi",
"Vendredi",
"Samedi",
"Dimanche"]
data = np.array([
[0,0,0,0,0,0,0,0,0,0,434,560,650,340,980,880,434,434,0,0,0,0,0,0],
[0,0,0,0,0,0,0,434,560,0,650,0,0,0,0,340,980,0,0,0,880,0,434,343],
[0,0,0,0,0,0,0,0,0,0,434,560,650,340,980,880,434,434,0,0,0,0,0,0],
[0,0,0,0,0,0,0,434,560,0,650,0,0,0,0,340,980,0,0,0,880,0,434,343],
[0,0,0,0,0,0,0,0,0,0,434,560,650,340,980,880,434,434,0,0,0,0,0,0],
[0,0,0,0,0,0,0,434,560,0,650,0,0,0,0,340,980,0,0,0,880,0,434,343],
[0,0,0,0,0,0,0,0,0,0,434,560,650,340,980,880,434,434,0,0,0,0,0,0]
])
fig, axis = plt.subplots() # il me semble que c'est une bonne habitude de faire supbplots
heatmap = axis.pcolor(data, cmap=plt.cm.Blues) # heatmap contient les valeurs
axis.set_yticks(np.arange(data.shape[0])+0.5, minor=False)
axis.set_xticks(np.arange(data.shape[1])+0.5, minor=False)
axis.invert_yaxis()
axis.set_yticklabels(row_labels, minor=False)
axis.set_xticklabels(column_labels, minor=False)
fig.set_size_inches(11.03, 3.5)
plt.savefig('test.png', dpi=100)
Run Code Online (Sandbox Code Playgroud)
非常感谢你的帮助 !
我正在学习 Sequelize,我发现有些东西很奇怪,所以我认为我做错了什么。
这是我对一个简单Posts表的迁移:
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Posts', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
title: {
type: Sequelize.STRING,
allowNull: false,
},
content: {
type: Sequelize.TEXT,
allowNull: false,
},
authorId: {
type: Sequelize.INTEGER,
onDelete: 'CASCADE',
allowNull: false,
references: {model: 'Users', key: 'id'}
},
publishedAt: {
type: Sequelize.DATE,
allowNull: true
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
}, …Run Code Online (Sandbox Code Playgroud) 我有两个模型,用户和事件.我invitations用一个status列在User和Event之间创建了一个数据透视表.在我的事件模型定义中,我写了这样的:
public function invited()
{
return $this->belongsToMany(User::class, 'invitations', 'event_id', 'user_id')
->withTimestamps()
->withPivot('status')
->orderByDesc('invitations.updated_at');
}
public function participants()
{
$event = $this->with([
'invited' => function ($query) {
$query->where('invitations.status', InvitationStatus::ACCEPTED)->get();
}
])->first();
return $event->invited;
}
Run Code Online (Sandbox Code Playgroud)
但是当我在我的控制器中时:
$event = Event::where('id', $id)->with(['owner', 'participants'])->first();
Run Code Online (Sandbox Code Playgroud)
我有以下错误:
(1/1) BadMethodCallException
Method addEagerConstraints does not exist.
Run Code Online (Sandbox Code Playgroud)
有人知道为什么吗?
我被困在这个我认为很简单的问题上。我有一个结构定义和一个采用该结构实例的函数。如何在 Ada 中调用此函数?这是一个示例代码:
定义.h:
typedef struct cartesian_t
{
float x;
float y;
float z;
} cartesian_t;
void debug_cartesian(struct cartesian_t t);
Run Code Online (Sandbox Code Playgroud)
定义.c
void debug_cartesian(struct cartesian_t t)
{
printf("%f, %f, %f\n", t.x, t.y, t.z);
}
Run Code Online (Sandbox Code Playgroud)
主文件
with Interfaces.C; use Interfaces.C;
with Ada.Text_IO;
procedure Main is
type Cartesian_Record_Type is record
X : C_Float;
Y : C_Float;
Z : C_Float;
end record
with
Convention => C;
procedure Debug_Cartesian(Cart : in Cartesian_Record_Type)
with
Import => True,
Convention => C,
External_Name => "debug_cartesian";
T : Cartesian_Record_Type …Run Code Online (Sandbox Code Playgroud) 目前正在学习 Ada 并真正享受它,有一个问题困扰着我:什么是tagged类型?根据 John Barnes 的 Programming in Ada 2012,它表示实例化的对象在运行时带有标签。
我在 C++ 或 CI 中从未听说过这样的事情,所以我有点迷茫。它是什么?我什么时候需要它(显然是为了拥有方法和继承?)?
我正在尝试使用Tweepy的用户的最后一条推文.这是我的代码:
class Bot:
def __init__(self, keys):
self._consumer_key = keys[0]
self._consumer_secret = keys[1]
self._access_token = keys[2]
self._access_secret = keys[3]
try:
auth = tweepy.OAuthHandler(self._consumer_key,
self._consumer_secret)
auth.set_access_token(self._access_token, self._access_secret)
self.client = tweepy.API(auth)
if not self.client.verify_credentials():
raise tweepy.TweepError
except tweepy.TweepError as e:
print('ERROR : connection failed. Check your OAuth keys.')
else:
print('Connected as @{}, you can start to tweet !'.format(self.client.me().screen_name))
self.client_id = self.client.me().id
def get_last_tweet(self):
tweet = self.client.user_timeline(id = self.client_id, count = 1)
print(tweet.text)
# AttributeError: 'ResultSet' object has no attribute 'text'
Run Code Online (Sandbox Code Playgroud)
我理解错误,但如何从状态中获取文本?Tweepy的文档很糟糕且不完整......
非常感谢您的帮助,
祝您度过愉快的一天!:)
我在rand项目中添加了依赖项:
[dependencies]
rand = "0.5"
Run Code Online (Sandbox Code Playgroud)
在我的中main.rs,我具有以下内容:
extern crate rand;
pub mod foo;
use foo::Foo;
fn main() {
println!("{:#?}", Foo::new());
}
Run Code Online (Sandbox Code Playgroud)
并在文件中foo.rs:
use rand::Rng;
#[derive(Debug)]
pub struct Foo { bar: bool }
impl Foo {
pub fn new() -> Foo {
Foo { bar: rand::thread_rng().gen_bool(0.5) }
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,出现以下错误:
error[E0658]: access to extern crates through prelude is experimental (see issue #44660)
--> src\foo.rs:11:18
|
11 | bar: rand::thread_rng().gen_bool(0.5)
| ^^^^
Run Code Online (Sandbox Code Playgroud)
如何使用模块中的外部包装箱?
我正在努力做到这一点
local ball = {
width = 20,
height = 20,
position = {
x = (game.width / 2) - (width / 2), -- Place the ball at the center of the screen
y = (game.height / 2) - (height / 2)
},
velocity = 200,
color = { 255, 255, 255 }
}
Run Code Online (Sandbox Code Playgroud)
但Love2D说我attempt to perform arithmetic on global 'width' (a nil value).我该如何解决?
我已经尝试过替换width / 2,ball.width / 2但我得到了attempt to index global 'ball' …
我正在尝试为程序生成随机字符串ID(该ID必须在程序执行期间才是唯一的).我首先在Python中做到没有任何问题:
class RandomIdGenerator:
_base_62_chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
@classmethod
def get_base_62(cls, length):
return "".join([random.choice(RandomIdGenerator._base_62_chars) for _ in range(length)])
Run Code Online (Sandbox Code Playgroud)
但是因为我需要我的程序使用C++,所以我试图用它生成相同的字符串.这就是我现在所做的:
void Node::setId()
{
QString allow_symbols("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
qsrand(QTime::currentTime().msec());
for (int i = 0; i < ID_LENGTH; ++i) {
id_.append(allow_symbols.at(qrand() % (allow_symbols.length())));
}
}
Run Code Online (Sandbox Code Playgroud)
我有两个主要问题.首先它不使用C++ 11(我不知道Qt是如何工作的,但我不认为它是C++ 11)并且生成的ID都是相同的.如果我生成其中四个我得到:
"R4NDM1xM"
"R4NDM1xM"
"R4NDM1xM"
"R4NDM1xM"
Run Code Online (Sandbox Code Playgroud)
我尝试使用C++ 11方法但是我得到了相同的结果,更糟糕的是,在每次执行时,我得到了完全相同的结果:
void Node::setId()
{
id_ = "";
const std::string str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
std::random_device rd;
std::mt19937 generator(rd());
std::uniform_int_distribution<int> dist(0, str.size() - 1);
for (int i = 0; i < Node::ID_LENGTH; ++i)
id_ += str[dist(generator)];
} …Run Code Online (Sandbox Code Playgroud) 当我不想在 Rust 匹配结构中做任何事情时,我可以执行以下两种方法之一:
match some_number {
1 => println!("One"),
2 => (), // unit value
_ => {} // ?
}
Run Code Online (Sandbox Code Playgroud)
有什么区别吗?{}不是单位值,那么它有什么作用呢?