# How to plot in grayscale with gadfly?

**URL:** <https://discourse.julialang.org/t/how-to-plot-in-grayscale-with-gadfly/78780>\
**Category:** Visualization\
**Tags:** gadfly\
**Created:** [March 31, 2022, 2:38am UTC](https://discourse.julialang.org/t/how-to-plot-in-grayscale-with-gadfly/78780 "2022-03-31T02:38:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 31, 2022, 2:38am UTC](https://discourse.julialang.org/t/how-to-plot-in-grayscale-with-gadfly/78780/1 "2022-03-31T02:38:50Z")

</div>

Hi,

I have some code roughly like this:

```julia
using DataFrames
using Gadfly
df = DataFrame(
    :percent_barrier => sqrt.(rand(100)) .* 100,
    :stop_reason => ifelse.(rand(100) .> 0.75, "Solved", "Timeout")
)
plot(
    df, x = "percent_barrier", color="stop_reason", Geom.histogram(;bincount = 10),
    Gadfly.Guide.xlabel("Time spent solving barrier (10% bins)"),
    Gadfly.Guide.ylabel("Amount of instances"),
    Guide.colorkey(; title = "Stop reason")
)

```

Which generates the following image:

![example](https://global.discourse-cdn.com/julialang/original/3X/e/8/e83c0bc2871ad3543d40a7aee2805fcf3909da2a.png)

In R, I remember that I just needed to pass some object/flag for it to use grayscale and it was done. I am, however, not finding an easy answer for `Gadfly`. There is some parameter that I can pass to any plot that use more colors than just black to make it grayscale?

---

<div class="post-metadata">

**Author:** ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)\
**Post date:** [March 31, 2022, 12:11pm UTC](https://discourse.julialang.org/t/how-to-plot-in-grayscale-with-gadfly/78780/2 "2022-03-31T12:11:03Z")

</div>

no there is not an easy way. it is possible though to specify all the color defaults with a custom Theme. Gadlfy has two built-in “named” themes: [Themes · Gadfly.jl](http://gadflyjl.org/stable/man/themes/#Named-themes). it would seem useful to have a greyscale theme too. care to submit a PR?

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 31, 2022, 2:10pm UTC](https://discourse.julialang.org/t/how-to-plot-in-grayscale-with-gadfly/78780/3 "2022-03-31T14:10:40Z")

</div>

I have read the description of the `Gadfly.Theme`, and it seems like more than I can handle right now, the following description of a field has also diminished my hopes:

> discrete\_colormap
> 
> A new Theme field, in development. Currently only works with Guide.manual\_discrete\_key and Guide.manual\_color\_key. (Function)

So I am not sure if the tools to implement a pervasive grayscale Theme exist currently.

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [March 31, 2022, 11:17pm UTC](https://discourse.julialang.org/t/how-to-plot-in-grayscale-with-gadfly/78780/4 "2022-03-31T23:17:48Z")

</div>

The current way to change to a discrete gray scale for a single plot is:

```julia
plot(df, x = "percent_barrier", color="stop_reason", 
    Geom.histogram(;bincount = 10),
    Scale.color_discrete_manual("gray10","gray50"),

```

Changing colorscales via `Theme` currently has some issues (see link in [https://github.com/GiovineItalia/Gadfly.jl/pull/1118](https://github.com/GiovineItalia/Gadfly.jl/pull/1118)). But these changes are now being rolled out in other PRs (as you see noted with `discrete_colormap`). The tables in the [Gadfly Tutorial](http://gadflyjl.org/stable/tutorial/#Discrete-Scales) show the current status.
