Accents and greek letters

Julia version: 1.4.1
Kubuntu: 18.04 LTS

Hello,

As a french-speaking person, I often use accentuated characters e.g., é (e-accute). When I run a simple code like this one:

using Plots

t(x) = cos(x)
u(x) = -sin(x)

plot(-π:0.01:π, [t,u],
		 linewidth = 2.0,
		 framestyle = :box, grid = :yes,
		 title="cos(x) et sa dérivée",
		 xlabel="x", 
		 ylabel="Valeurs",
		 lab=["f(x)" "f'(x)"])
		 
plot!(size=(600, 400))

savefig("figure_cosinus_et_derivee_1.png")

I obtain an error and in the graph, each é is replaced by an empty rectangle:

GKS: character ignored due to unicode error

In the same vein, greek letters are replace by ?

Do you know how to circumvent this(these) problem(s) by using Plots?
Thank you in advance,
Thierry

2 Likes

Perhaps this is solved, Unicode Support in Julia 1.0 · Issue #143 · jheinen/GR.jl · GitHub suggests that you can enable unicode like so:

ENV["GKS_ENCODING"]="utf-8"
using Plots
gr()
plot(1:10; xlabel="ε")
3 Likes

Thank you very much, macabbott. This works fine. :+1:
As suggested in the link you sent me, I inserted

ENV["GKS_ENCODING"]="utf-8" 

in startup.jl

1 Like

In the same simple code as described above, how can I obtain -π, -π/2, etc., on the X-axis instead of -3.14, -1.57, etc?

And how to represent for example units in the form of ms-² instead of ms^-2 on a given axis typically?

One way to give labels for ticks is like so: plot(rand(5), xaxis=("ex", (0,7), ([1,2,3,4], ["one", "II", "3/\\(1\\)", "\\ 4^(1)"]) )). GR has a mode in which it displays fractions & exponents, which I though giving \\alpha etc. would activate, but a quoted space like \\ seems to work too… perhaps there is a more official way.

Thank you very much macabbott. :+1:
I am working on your solution in order to adapt it.

However I though that:

  • some kind of “formatter” could be a solution (Axis Attributes · Plots) or,
  • something like “curve.relabel” (holoview in Python) could be found in Plots.

Kind regards,
Thierry

I tried your command and it works. :wink: Many thanks.

However, I turned towards GnuPlot and its Julia interface, i.e., Gaston in order to use “gpcom” commands of GnuPlot which make the code easy to read (IMHO). Here is an example of a very elementary code which works even though I am sure that it is not very instructive for Julia geeks as you. [The xlabel is just for fun (a trial to obtain upperscript in units)]. More interesting is the fact that this code is much more rapid (~10 times) than its Plots equivalent.

using Gaston

t = 0.0:0.01:2π

plot(t, cos.(t),
        xrange="[0.0:*]",
        yrange="[-1.2:1.2]",
        title="Circular function", 
        grid="on", 
        xlabel="Frequency (s^⁻^1)", 
        ylabel="Amplitude",
        keyoptions="box top right", 
        legend="cos(t)",
        linecolor="red",
        gpcom="set xtics pi; set format x '%.0Pπ'"          # GnuPlot command
    )

printfigure(term="png", font="Times,16", size="1000,650",
            linewidth="1", background="white",
            outputfile="cosinus.png")

Kind regards,
Thierry

I’ve started getting this error when generating plots where tick mark labels are of the form 3X10^4 : the X doesn’t appear and the labels are distorted as shown in the attached figure. This must be associated with some recent change, I think, since I didn’t used to have the problem. I have inserted ENV["GKS_ENCODING"]="utf-8" before plotting, but that doesn’t fix the error.

Any tips?

image

Hello lwhitefox,
Is ENV[“GKS_ENCODING”]=“utf-8” inserted in startup.jl?
What is your julia version?
Are you dealing with using Plots?

I put this right before generating the plots not in startup.jl (yes, with the Plots package.

This is with Julia 1.4.1 ; I ran update in pkg mode a few days ago so Plots should be current - in fact it was after updating that the problem started

Maybe a problem of fonts?

Is there an easy way to specify a font family?

Again this is weird (To me) because it is a new problem.

I think that this thread could help you: Changing fonts in pyplot · Issue #482 · JuliaPlots/Plots.jl · GitHub