Comments (8)
Example 2 below works!
Example 1
n = 100
@btime g1 = compose(context(),
(context(), Compose.circle(rand(n),rand(n),rand(n)/100), fill(["red" for i in 1:n]), stroke(nothing))
)
39.532 μs (635 allocations: 26.56 KiB)
Example 2
@btime g2 = compose(context(), stroke(nothing),
(context(), Compose.circle(rand(n),rand(n),rand(n)/100), fill("red")),
(context(), Compose.circle(rand(n),rand(n),rand(n)/100), fill("gray"))
)
6.579 μs (464 allocations: 22.78 KiB)
contexts
(per group) are cheaper than properties- save Example 1 as an svg (with
n=10
andn=100
). and open in a text editor (the fills per point disappear forn=100
). - probably a gc issue
from compose.jl.
Yes. Example 2 works. The issue is that in GraphPlot, the recipes have several properties for each group (stroke
, fontsize
, etc), so we see the error when networks have many nodes or edges, but not all properties are given vector inputs.
Are you saying that this is not an issue with Compose, but an issue with gc?
from compose.jl.
For example, consider Geom.line
in Gadfly (link to Geom.line code). It takes a "subgroup first, plot later" approach.
Also did you try saving the image before you plot it in a notebook e.g.:
draw(PDF("test.pdf"), g)
draw(PNG(), g)
from compose.jl.
My concern is what is at the root of the problem? What is causing the fill color to disappear?
This issue arises from the fact that GraphPlot.jl
uses Compose to generate a graph plot:
compose(
context(units=UnitBox(-1.2, -1.2, +2.4, +2.4)),
compose(context(), texts, fill(nodelabelc), fontsize(nodelabelsize)),
compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)),
compose(context(), edgetexts, fill(edgelabelc), fontsize(edgelabelsize)),
compose(context(), arrows, stroke(edgestrokec), linewidth(edgelinewidth)),
compose(context(), lines, stroke(edgestrokec), linewidth(edgelinewidth)),
compose(context(), rectangle(-1.2, -1.2, +2.4, +2.4), fill(background_color)))
So if say the fill of the nodes in the graph is a vector, but the linewidth AND nodestroc color are not vectors, then the colors disappear after 100 nodes.
We could make the plot longer by adding each node with its stroke and linewidth in a loop, but I'm not sure why we this strange behavior occurs after 100 nodes.
from compose.jl.
I would have to investigate what the root cause is. The general issue here is that because of the design of Compose, property vectors are expensive (so the solution might turn out to be "Compose 2"). Out of interest, what is on average length(unique(nodefillc))
.
from compose.jl.
I see. It really depends on the application. Some networks can have a few nodes, others can also be in the hundreds. You could have 100 nodes with only 2 colors, but the parameter would be a 100 element vector (2 unique values). The number of unique colors should typically be small (less than 10, otherwise the colors are just confusing)
I find that if I make all the parameters for the nodes to be vectors of the same length, the issue disappears and the color is preserved. So I don't know if it could have anything to do with broadcasting...
from compose.jl.
Yes I was asking about the number of unique colors. Since the (no. of colors)/(no. of points) is small, then having a context per color sounds more Composesque (it is also the way that backends such as svg were designed ie one fill color per group is better than a fill color for each point).
from compose.jl.
I see. We might rethink the way we build our plots then. Thanks for the insight.
Another workaround I've found is to directly pipe the plot to SVG rather than creating it and then saving it as SVG. When I do this, the color isn't lost.
from compose.jl.
Related Issues (20)
- Compatibility with GeometryBasics? HOT 2
- Revise + Requires + Cairo + Fontconfig + Compose produces a pango error HOT 1
- ngon and xgon are transformed incorrectly in UnitBox? HOT 1
- Compose docs not deploying HOT 3
- tests fail on 1.6
- TagBot trigger issue HOT 9
- Guidance on a hyperbolic drawing extension
- `introspect` for graphs which are not trees
- Improve documentation for introspect HOT 1
- Document type hierarchy? HOT 1
- Make display in the REPL
- using Gadfly causes Method error in AlgebraOfGraphics.draw() HOT 2
- how to use SVG attributes?
- Dangerous pirate of `fill` function
- Inconsistencies when saving to a stretched image? HOT 2
- tests fail in windows 11 HOT 1
- Rectangle rotation doesn't work HOT 3
- Bitmaps (at least, SVGs) do not rotate in a `context(..., rotation=Rotation(θ)`
- Unsupressable output to stdout(?)
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 compose.jl.