Comments (2)
That's a fun one -- and actually not really the fault of Graph
; it's a consequence of the behavior of dict.fromkeys
. You can check that this version (after slightly increasing the vertex radius) renders correctly:
import manim as mn
class KonigsbergBridgeNotWorking(mn.Scene):
def construct(self):
self.camera.background_color = mn.DARKER_GREY
title_text = mn.Text(text="KonigsbergBridgeNotWorking", color=mn.WHITE).shift(
mn.UP * 3.5
)
vertices: list = [0, 1, 2, 3]
edges: list = [(0, 1), (0, 2), (0, 3), (1, 0), (1, 2), (2, 3), (3, 0)]
graph = mn.Graph(
vertices=vertices,
edges=edges,
labels=True,
vertex_config={v: {"color": mn.PINK, "radius": 0.3} for v in vertices},
edge_type=mn.Line,
edge_config={e: {"path_arc": mn.PI / 4, "color": mn.WHITE} for e in edges},
)
self.play(mn.AddTextLetterByLetter(title_text))
self.play(mn.Create(graph))
self.wait(3)
The issue with dict.fromkeys
is that if you use a dictionary (as a complex data type) as a value, the separate values will actually just be shallow copies of each other; they reference the same dict under the hood. Here is a plain example illustrating this behavior:
>>> conf = {'x': 1, 'y': 2}
>>> dct = dict.fromkeys([7, 8], conf); dct
{7: {'x': 1, 'y': 2}, 8: {'x': 1, 'y': 2}}
>>> dct[7]['x'] = 42
>>> dct
{7: {'x': 42, 'y': 2}, 8: {'x': 42, 'y': 2}}
The Graph
mobject doesn't have any safeguards to fix this internally, the identical config dicts appear to mess things up in a weird way. You can check that by printing the value of graph._vertex_config
; its entries will all be the exact same dict.
from manim.
Wow, just looked at the docs and your example - you're totally right. You learn something new every day. With the fault being dict.fromkeys
passing a reference to the same instance, I'd wager that it's not worth it to put a check in the Graph
constuctor.
Thanks for the help! You think this one can be closed out?
from manim.
Related Issues (20)
- add_subcaption does not work as expected HOT 1
- Error when using `next_to` to a ImageMobject with the OpenGL renderer
- Fix setup-ffmpeg - unable to fetch HOT 2
- Manim installation not working with conda and python 3.12.3
- Issue with installing manim on google colab; fixed issue and just wanted to inform
- pwntools compatibility issue due to gdb related problems HOT 1
- V0.18.1 NumberLine's number_to_point() is broken when using `add_tip` HOT 1
- Google Colab: Video data is no longer automatically embedded in the notebook HOT 1
- Manim stuck in python 3.12.3 on arch linux, and keeps allocating memory until no memory available. HOT 3
- Underline markup tag for MarkupText should be documented as <u></u> not <ul></ul>. HOT 1
- Latex error HOT 6
- FadeOut on DiGraph does not work smoothly HOT 1
- Autoaliasattr: `TypeVar`
- Error with Graph Tree Layout example in the graph.py HOT 3
- `VGroup` cannot have a `Mobject` as a child, but `VMobject` can
- I want to know there is a threeD table in Mainm? HOT 2
- always_redraw works in 0.18.0 but not in 0.18.1 (single ValueTracker) HOT 5
- cmanimpango fatal error: Python.h HOT 3
- Support Python 3.12 `TypeAlias` syntax
- Can not use \textcolor , always render as white color HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from manim.