How to put filepath as title in plots?

Hello!

Suppose I have a complete filepath on Windows:

C:\Users\MyAccount\My System Drive - On This PC\FileYay.txt

And when I need to load this file, I can simply do so by using raw infront of it, and it will escape properly.

Then I want to make a plot and use this path as the title, but it just tells me undefined symbol. How can I circumvent this?

Example code:

filepath = raw"C:\Users\MyAccount\My System Drive - On This PC\FileYay.txt"
using Plots
plot()
title!(filepath)

Output:

title!(filepath)
\Users\MyAccount\My System Drive \- On This PC\FileYay.txt: undefined symbol
\Users\MyAccount\My System Drive \- On This PC\FileYay.txt: undefined symbol
\Users\MyAccount\My System Drive \- On This PC\FileYay.txt: undefined symbol

Kind regards

The best I could find is to replace \ by /:

title!(replace(filepath,"\\" => "/"))

Edit: there is also the \setminus unicode symbol:

julia> title!(replace(filepath,"\\" => "∖"))

image

2 Likes

Thanks!

1 Like

You can also pass your title string twice through escape_string, i.e. escape_string(escape_string(filepath)).

I don’t know if the need to do it twice is normal or a bug.

3 Likes

Using LaTeXStrings.jl:

using Plots, LaTeXStrings
filepath = raw"C:\Users\MyAccount\My System Drive - On This PC\FileYay.txt"
plot()
title!(L"\textrm{%$filepath}",titlefontsize=10)

Windows_path_on_plots_with_LaTeXString

1 Like

Thanks @sijo and @rafael.guerra !

I had actually tried escape_string (only once though) and then gave up on it…

The approach using LaTeXStrings also seems quite nice.

Kind regards

1 Like