Julia LatexStrings plotting text subscripts - matplotlib

I am using PyPlot to plot things in Julia. I want my plot label to use LateX fonts so I'm using LatexStrings.
I would like to write a variable with subscript such that the subscript is not written in italics, i.e in Latex: $z_{\text{eff}}$.
The closest I can get with LatexStrings is L"z_{eff}" however the subscript is written in italics in that case.
Is what I am looking for possible with these packages (I don't want to switch to something other than PyPlot)?

You can do
L"z_{\mathrm{eff}}"
if you don't mind using \mathrm instead of \text to make the subscript be upright and non-italic.
L"z_{\text{eff}}" works in LaTeXStrings by itself, but sending that on to PyPlot messes something up. Things like \mathtt and \rm also work, but \textnormal and \textrm don't.

Related

seaborn from distplot to displot new input parameters

as Seaborn warned to prefer 'displot' to future deprecated 'distplot', I'm trying to change old codes. Unfortunately I find a bit hard finding corresponding parameters for several inputs. Just an example: below I start with the old 'distplot' code working:
c=np.random.normal(5,2,100)
sns.distplot(c,hist=True,kde=True,color='g',kde_kws={'color':'b','lw':2,'label':'Kde'},hist_kws={'color':'purple','alpha':0.8,
'histtype':'bar','edgecolor':'k'})
Now, I want to show the same result with 'displot' but I don't know how to put 'alpha' for histogram as well as all the 'hist_kws' stuff. Below how I started:
sns.displot(data=c,kind='hist',kde=True,facecolor='purple',edgecolor='k',color='b',
alpha=1,line_kws={'lw':2})
I'm looking for a better documentation but I didn't have luck so far

Harfbuzz - Text to Glyph to Text

Recently, I came across Harfbuzz for text shaping, specifically for Indic texts. In my previous experience, I used ArabicShaping for shaping Arabic characters. In this case, the input is the pre-shaped text and the output is the shaped one.
In Harfbuzz, however, I can see the shape method shapes the text and returns the glyphs and the clusters instead. My objective is to convert the pre-shaped text to a shaped one. I don't want to draw/view the text. I just want a char[] which will contain the shaped one (just like in case of ArabicShaping).
Is there any way the above can be achieved using Harfbuzz? If not, is there any workaround?
Am I using Harfbuzz for solving the correct problem? Is there any other library that I can use to achieve this?
ArabicShaping must have confused you. There's no such thing as "pre-shaped text" in general. What do you mean "convert the pre-shaped text to a shaped one"? Shaping, what HarfBuzz does, converts from characters to glyphs. The reverse is a non-deterministic process that HarfBuzz does NOT provide.

How to align a number to the right in Jupyter notebook math mode

Apologies if this is a stupid question, but I searched a lot and couldn't find out how to do this. In math mode if I'm trying to write the equations
$$x=2 x=3$$
How do I align the x=3 to the right side of the page? I tried \hfill but it didn't seem to do anything. Thanks!
Placing right-align text with markdown code is not possible. However, if you add a \tag{xx}, i.e. for equation number, you get the tag's content on the right side. And the the equation in the center. For example:-
$$x=2 x=3 \tag{2.a}$$
You get something like: x=2 x=3 (2.a)
To get what you want, you need to use HTML code instead. For example, write this code:
<div style='text-align: right'><em>x=2 x=3</em></div>
in a markdown cell and run it, you should get the result you want.

Combining a format string with a superscript and a subscript in pyplot when rendering text in a plot

I would like to include the equation for a "power-law" curve I am creating using pyplot. I have tried several variations of the following code:
ax.text(0.1,0.9,r'{0:}x$^{1:}$'.format(A,b))
of course the text renderer uses the curly brackets as well as the format statement. I have tried doubling the curly brackets to have
ax.text(0.1,0.9,r'{0:}x$^{{1:}}$'.format(A,b))
and even tripling them
ax.text(0.1,0.9,r'{0:}x$^{{{1:}}}$'.format(A,b))
I have also tried splitting the text into two lines
exponent = '{0:}$'.format(b)
ax.text(0.1,0.9,r'{0:}x$^'.format(A)+exponent)
none of these really make sense to me or to pyplot, but I can't seem to ask the right search question to get this to work. I have found answers that suggested splitting the line and using double curly brackets but nothing that will make this work. Is this possible?
EDIT:
Through further experimentation I have answered the question above which was a simplified version of the equation I wanted to put in the plot, so let me change this question slightly. To do what I wanted above I have found that:
ax.text(0.1,0.9,r'{0:}x$^{{ {1:} }}$'.format(A,b))
works. I don't know why I hadn't tried it earlier, but I have now. The problem is that I actually want a subscript on x as well. Given that the above works I would have thought that:
ax.text(0.1,0.9,r'{0:}x$^{{ {1:} }}_{{\rm map}}$
would work, but I get the following error:
Subscript/superscript sequence is too long. Use braces { } to remove
ambiguity. (at char 0), (line:1, col:1)
I cannot see where to add braces that will remove any ambiguity. Can anyone tell me what I need to do?
This works:
ax.text(0.1, 0.9, r'${0:}x^{{{1:}}}_{{\rm map}}$'.format(A, b))
The issue was that your x was outside of the mathmode ($...$).
With regards to the double curly braces, there is an easy explanation: When using the format function all single curly braces are matched with an argument to the format function (they can also be nested). Two subsequent curly braces are the defined way of getting one curly bracket after applying format. See the documentation for more information on this.

Set histogram ticks/label using Syntax

Let me preface this by saying that I am a programmer by trade, but not very familiar with SPSS.
I am helping a friend set up some histogram plots using SPSS Syntax language. Using the Chart Builder, we have arrived at the code below:
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=OurVariable MISSING=LISTWISE REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE
TEMPLATE=[
"C:\some\path\greenHistogram.sgt"].
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: OurVariable=col(source(s), name("OurVariable"))
GUIDE: axis(dim(1), label("OurVariable"))
GUIDE: axis(dim(2), label("Frequency"))
GUIDE: text.title(label("Bla bla",
"bla"))
ELEMENT: interval(position(summary.count(bin.rect(OurVariable, binStart(0.5)))),
shape.interior(shape.square))
END GPL.
As you can see, she would like to make the histogram columns green. We could not achieve that using the Chart Builder, but we could easily make a template via the Chart Editor window and apply that. This seems like a very sensible approach, as she has many charts she wants green.
She would also like to customize the y-axis labels (number of decimal places, tick "major increment" etc.). This can also be achieved using the Chart Editor and saving a template. However, this is a much more individualized edit, and making a custom template for each and every plot seems cumbersome. Is it possible to adjust these things directly in the Syntax-script which generates the plots?
In many other places there is a nice Paste-button which generates the necessacy code, but I could not find one in the Chart Editor.