Skip to content

Commit ded3fc5

Browse files
authored
Merge pull request #127 from nomadbl/add_gadfly
add native support for Gadfly plots
2 parents 3560be6 + 3f45cbd commit ded3fc5

File tree

6 files changed

+47
-4
lines changed

6 files changed

+47
-4
lines changed

Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ StatsBase = "0.27, 0.28, 0.29, 0.30, 0.31, 0.32, 0.33, 0.34"
2020
julia = "1.6"
2121

2222
[extras]
23-
Minio = "4281f0d9-7ae0-406e-9172-b7277c1efa20"
2423
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
2524
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
2625
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
2726
MLDatasets = "eb30cadb-4394-5ae3-aed4-317e484a6458"
27+
Minio = "4281f0d9-7ae0-406e-9172-b7277c1efa20"
2828
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
2929
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
30+
Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004"
31+
Cairo="159f3aea-2a34-519c-b102-8c37f9878175"
32+
Fontconfig="186bb1d3-e1f7-5a2c-a377-96d770f13627"
3033
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3134
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
3235
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ logger in Julia:
3939

4040
You can log to TensorBoard any type. Numeric types will be logged as scalar,
4141
arrays will be binned into histograms, images and audio will be logged as such,
42-
and we even support [Plots](https://github.com/JuliaPlots/Plots.jl) and
43-
[PyPlot](https://github.com/JuliaPlots/Plots.jl) figures!
42+
and we even support [Plots](https://github.com/JuliaPlots/Plots.jl),
43+
[PyPlot](https://github.com/JuliaPlots/Plots.jl) and [Gadfly](https://github.com/GiovineItalia/Gadfly.jl) figures!
4444

4545
For details about how types are logged by default, or how to customize this behaviour for your custom types,
4646
refer to the documentation or the examples folder.
@@ -71,7 +71,7 @@ end
7171
```
7272

7373
## Integration with third party packages
74-
We also support native logging of the types defined by a few third-party packages, such as `Plots` and `PyPlot` plots.
74+
We also support native logging of the types defined by a few third-party packages, such as `Plots`, `PyPlot` and `Gadfly` plots.
7575
If there are other libraries that you think we should include in the list, please open an issue.
7676

7777
## Roadmap

docs/src/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ at [Reading back TensorBoard data](@ref)
111111
We also support logging custom types from a the following third-party libraries:
112112
- [Plots.jl](https://github.com/JuliaPlots/Plots.jl): the `Plots.Plot` type will be rendered to PNG at the resolution specified by the object and logged as an image
113113
- [PyPlot.jl](https://github.com/JuliaPy/PyPlot.jl): the `PyPlot.Figure` type will be rendered to PNG at the resolution specified by the object and logged as an image
114+
- [Gadfly.jl](https://github.com/GiovineItalia/Gadfly.jl) type will be rendered to PNG at the resolution specified by the object and logged as an image. `Cairo` and `Fontconfig` packages must be imported for this functionality to work as it is required by `Gadfly`.
114115
- [Tracker.jl](https://github.com/FluxML/Tracker.jl): the `TrackedReal` and `TrackedArray` types will be logged as vector data
115116
- [ValueHistories.jl](https://github.com/JuliaML/ValueHistories.jl): the `MVHistory` type is used to store the deserialized content of .proto files.
116117

examples/Gadfly.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using TensorBoardLogger #import the TensorBoardLogger package
2+
using Logging #import Logging package
3+
using Gadfly, Cairo, Fontconfig
4+
5+
logger = TBLogger("Gadflylogs", tb_append) #create tensorboard logger
6+
7+
################log scalars example: y = x²################
8+
#using logger interface
9+
x = rand(100)
10+
y = rand(100)
11+
p = plot(x=x, y=y, Geom.point);
12+
with_logger(logger) do
13+
@info "gadfly" plot=p
14+
end

src/Optional/Gadfly.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import .Gadfly: Plot, render, draw
2+
function Base.convert(t::Type{PngImage}, plot::Gadfly.Plot)
3+
pb = PipeBuffer();
4+
show(pb, MIME("image/png"), render(plot));
5+
# draw(Gadfly.PNG(pb), plot); # leaving here for now, does same thing
6+
return PngImage(pb)
7+
end
8+
9+
preprocess(name, plot::Gadfly.Plot, data) = preprocess(name, convert(PngImage, plot), data)
10+
preprocess(name, plots::AbstractArray{<:Gadfly.Plot}, data) = begin
11+
for (i, plot)=enumerate(plots)
12+
preprocess(name*"/$i", plot, data)
13+
end
14+
return data
15+
end

src/TensorBoardLogger.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ function __init__()
102102
@require PyPlot="d330b81b-6aea-500a-939a-2ce795aea3ee" begin
103103
include("Optional/PyPlot.jl")
104104
end
105+
@require Gadfly="c91e804a-d5a3-530f-b6f0-dfbca275c004" begin
106+
@require Fontconfig="186bb1d3-e1f7-5a2c-a377-96d770f13627" begin
107+
@require Cairo="159f3aea-2a34-519c-b102-8c37f9878175" begin
108+
using .Cairo
109+
using .Fontconfig
110+
include("Optional/Gadfly.jl")
111+
end
112+
end
113+
end
114+
# @require Gadfly="c91e804a-d5a3-530f-b6f0-dfbca275c004" include("Optional/Gadfly.jl")
105115
@require Tracker="9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c" begin
106116
include("Optional/Tracker.jl")
107117
end

0 commit comments

Comments
 (0)