小编Mar*_*ark的帖子

带孔的Matplotlib补丁

以下代码有效。问题是我不知道它为什么起作用。该代码绘制了一个圆形补丁(使用PathPatch),该补丁的中心为三角形。我的猜测是切掉了内部三角形,因为它是顺时针绘制的,而外部圆是逆时针绘制的。如果方向不反向,三角形将不会被切除。我没有在文档中找到有关所使用规则的任何信息。那为什么行得通呢?

from matplotlib import pyplot
from matplotlib.path import Path
from matplotlib.patches import PathPatch
import numpy

#
# draw a triangle within a circle using PathPatch
#
phi = numpy.linspace(0, 2*numpy.pi, 100)
circle = 4 * numpy.exp(1j * phi)
circleV = [[p.real, p.imag] for p in circle]

phi = numpy.linspace(0, 2*numpy.pi, 4)
triangle = 2 * numpy.exp(1j * phi)
triangleV = [[p.real, p.imag] for p in triangle]

circleC = [Path.LINETO for p in circleV]
circleC[0] = Path.MOVETO
triangleC = [Path.LINETO for …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

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

在 Rust 中克隆一个 Rc 指针到一个特征对象上?

我正在学习 Rust,不明白为什么以下内容不起作用。我想我们无法在特征对象上克隆 Rc 指针?我如何将这样的引用传递给仅由特征定义的函数,如尝试的那样some_function

use std::rc::Rc;

trait SomeTrait {}
struct SomeThing {}
impl SomeTrait for SomeThing {}

fn some_function(s: Rc<dyn SomeTrait>) {}
fn another_function(s: &Rc<dyn SomeTrait>) {}

fn main() {
    let s = Rc::new(SomeThing{});

    // This doesnt work
    some_function(Rc::clone(&s));

    // I could do this
    some_function(s);

    // But then I could not do this
    some_function(s);
    
    // For that matter, neither can I do this
    another_function(&s);
}
Run Code Online (Sandbox Code Playgroud)

smart-pointers traits rust trait-objects

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

PySide Qt 在叶项中插入行并更新视图

我有这个主要工作的代码,使用户能够将项目添加到树结构中。只要您不向叶项(没有子项的项)添加项,这就可以正常工作。

如果该项目没有子项,则在第一次添加子项时,视图根本不会更新。您可以通过卷起父项并重新展开它来更新视图。或者,添加第二个子项会导致视图更新(并且您可以看到添加的两个项)。

将第一个子项添加到叶项后,如何更新视图?

更新:您也可以双击新的父项,将显示其子项,但不会显示扩展小部件。看起来没有发生的是,在满足上述条件之一之前,小扩展项小部件不会显示。

from PySide import QtCore, QtGui
import sys


model_data = [
    [1, [2, [3, 4]]],
    [5, [6, 7]],
    [8, [9]],
    [10]
]


class MyData:

    def __init__(self, number, parent=None):
        ''''''
        self.number = number
        self.children = []
        self.parent = parent
        if parent is not None:
            parent.addChild(self)


    def row(self):
        ''''''
        row = None
        if self.parent is None:
            row = 0
        else:
            for i, item in enumerate(self.parent.children):
                if item == self:
                    row = i
                    break

        return row


    def addChild(self, item):
        '''''' …
Run Code Online (Sandbox Code Playgroud)

python qt qtreeview pyside qabstractitemmodel

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

使用Sympy在3D中绘制曲线

如何使用Sympy绘制以下3D曲线(作为示例)?我知道只需为t创建一个数组并在Matplotlib中执行此操作,但我不想绘制曲线,而是学习如何以符号方式定义和绘制曲线.

alpha(t)=(cos(t),sin(t),t)

from sympy import *

t = symbols('t')
alpha = [cos(t), sin(t), t]

# now what?
Run Code Online (Sandbox Code Playgroud)

我尝试过以各种方式使用绘图方法,但这只会导致三条单独的1D曲线或错误.

python plot curve sympy mplot3d

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

如何在 cmake 中使用 COMPONENTS 配置项目

我想使用 cmake 创建一个项目项目,它的访问方式与 Poco 使用的方式类似。我发现使用 Poco 作为示例很拥挤且难以理解,因此我尝试创建一个最小版本,没有宏,以便我可以看到发生了什么。我在这里为这个例子构建了一个存储库。

https://github.com/markeastwood82/nomnoms

这个,以及下面写的内容,是我在阅读/解决“现代 CMake”几天后如何解决这个问题的最佳猜测,除了它不太有效。基本上我有一个图书馆noms用组件fruitveg我想从应用程序动态链接munch。我可以安装该noms库,但无法使用munch. 有人可以帮我把这个东西放在一起吗?

这两个项目的结构如下:

noms
|---- CMakeLists.txt
+---- fruit
|     |---- CMakeLists.txt
|     |---- fruit-config.cmake.in
|     +---- src
|     |     |----apple.cpp
|     |
|     +---- include/noms/fruit
|           |----apple.h
|
+---- veg
      |---- CMakeLists.txt
      |---- veg-config.cmake.in
      +---- src
      |     |---- asparagus.cpp
      |
      +---- include/noms/veg
            |---- asparagus.h
Run Code Online (Sandbox Code Playgroud)
munch
|---- CmakeLists.txt
+---- src
      |---- main.cpp

Run Code Online (Sandbox Code Playgroud)

该文件noms/CMakeLists.txt包含以下内容。

cmake_minimum_required(VERSION 3.0)
set(project noms)
set(version …
Run Code Online (Sandbox Code Playgroud)

c++ components cmake

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

python字典中的键

我遇到的问题分布在许多源文件中,我以简单的线性格式重现问题的尝试失败了。尽管如此,我遇到的问题只是简单地描述了。

我有一个类Path为我实现__hash____eq__

我有一个类型Path为 a的项目,dict证明如下

path in list(thedict)
>> True
Run Code Online (Sandbox Code Playgroud)

我确认path == other,并hash(path) == hash(other)id(path) == id(other)那里other取直出的项目list(thedict.keys())。然而,我得到以下

path in thedict:
>> False
Run Code Online (Sandbox Code Playgroud)

并尝试以下结果 KeyError

thedict[path]
Run Code Online (Sandbox Code Playgroud)

所以我的问题是,在什么情况下这可能?我原以为如果path是 inlist(thedict)那么它必须在thedict.keys(),因此我们必须能够写thedict[path]. 这个假设有什么问题?

更多信息

如果有帮助,下面列出了有问题的类。正是在SpecificationPath上述问题被观察到的水平

class Path:
    pass

@dataclass
class ConfigurationPath(Path):
    configurationName: str = None
    
    def __repr__(self) -> str:
        return self.configurationName

    def __hash__(self):
        return hash(self.configurationName)

    def __eq__(self, …
Run Code Online (Sandbox Code Playgroud)

python hash dictionary

0
推荐指数
1
解决办法
67
查看次数