Custom versus Package function names

I think I am having issues with my custom function grid conflicting with the Plots package grid .

How can I specify (is “qualify” the better term?) that I want to use my own? To specify Plots’ version, I would do Plots.grid.

I’m having a strange issue where my resulting data changes when I generate a pyplot heatmap - if I comment out the heatmap line, results are correct and consistent after several executions; if I activate it again, results change after every few executions. I checked that this doesn’t happen with GR heatmap. I’ve tried but have not worked out a MWE, so I won’t go too in-depth here.

One solution could be to only import the heatmap function from the Plots package. What would be the syntax if I want the GR heatmap? using Plots.gr.heatmap ?

Another option would be to simply rename my function. Hoping to find a more elegant solution.

when you have conflicting names of functions, you must use qualifiers:

Package1.function_name
Package2.function_name

1 Like

If you just use import Plots then you will be forced to prepend all calls to Plots.jl functions with Plot. and I think that will resolve the conflict at the expense of some extra verbosity on your plotting calls.

This may be the right call. Does import differ from using in that you now must prepend all calls to Plots functions with Plot?

Since we’re here…what would be the correct syntax for specifying a backend? Plots.gr.heatmap?

I think you just set the backend, and then if you use heatmap, the Plots package will know it has to use the heatmap from GR backend

Look here: http://docs.juliaplots.org/latest/generated/gr/#gr-examples

1 Like

Right, but what if I want to use a qualifier for my own function? What is the syntax then?

This seems to be the best solution for me for exactly the reasons you note. Appreciate the help!

1 Like

Instead of always having to write Package. you can create a constant eg. const P = Package. From now on you can use P. instead of Package. if that is too verbose for you.

1 Like

Yes, but not only. With import, you can now redefine and add methods to functions of the package. For example, I could do

julia> import Plots

julia> Plots.heatmap(x::String) = "This is not a plot"

julia> Plots.heatmap("foo")
"This is not a plot"

julia> Plots.heatmap(x,y,z) = "Broke this one too"

julia> Plots.heatmap(1:10, 1:10, rand(10,10))
"Broke this one too"

I think the correct way is more

julia> using Plots

julia> gr()
Plots.GRBackend()
1 Like

Yes, when importing Plots the syntax is:

import Plots; Plots.gr() or Plots.pyplot()

and to check which backend is being used, Plots.backend()

Appreciate the info!