Python Matplotlib string-formatting in plots with bold and Italic font - python-3.x

I have a little problem with bold and italic fonts in a plot at the same time.
I tried:
plt.text(0.5,0.5,r'\it{italic} + \bf{bold}' = \it{\bf{both}}')
this gives: italic and bold = both
and with:
plt.text(0.5,0.5,r'\it{italic} + \bf{bold}' = \bf{\it{both}}')
I get: italic and bold = both
But what I want to get is both
I also tried to use the latex version with \textbf{...} and \textit{...} and the commands \mathit{...} and \mathbf{...}.
They work as they should but not if they are used combined. The combination of different "technologies" like \mathbf{\textbf{...}} does not help. It is alway only the last style that stays.
I saw a few different questions on that topic but no correct answer, so I hope that asking espacially for this contextless case helps to find an answer. I am looking for a generall solution, not for a workaround for a special case, e.g. using a special font that already looks bold.

I have found the answer. Yoi have to use a different font. The work around I mentioned is the answer. If you use:
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
you will get the desired result. The default font in matplotlib seems to not support the bold and italic edits at the same time. Maybe this helps in many other situations you will have with other edits in case you are looking for different combinations.

Related

How to make the `CocInlayHints` background color transparent in `.vimrc`

This is a follow up question to Change the color of the type hint in coc.nvim's rust-analyzer
I'm wondering if it's possible to change the background color of inlay hints from Rust Analyzer in Vim. Adding a hex #ffffff00 doesn't seem to work, nor does just 0.
After some more experimenting I was able to find that if you just remove the option for a background color in the examples provided in the aforementioned question, it will not have a background as desired. For me, that looks like:
"For Types hint
hi default CocInlayHint ctermfg=71
The part to remove is ctermbg=0. I also removed other parts from the example provided but it seemed to have no effect so I've left them out here as well.

How to print text with multiple different types of colors in he same line in Python 3?

I am trying to do some visualizing data on the terminal and I am doing lots of printing to do that. The issue I am having is that certain character symbols look the same. I figured that coloring them differently would help me see the differences. I see from this link that there is a way to do it, but I don't understand what I am looking at. There is no explanation for what is going on in those solutions.
How do you specify, in the same line, text with different colors?
I should also mention that I am building the printable string OUTSIDE of the call to print(). How do you build the colorful string outside of the print() call?
A rewritten form of my question:
1. Colorize the text I print to the string with multiple types of colors.
2. Colorize the string BEFORE it gets sent to the "print()" call.
A couple examples would be great.
Using colorama just like the answer you linked is doing:
from colorama import Fore, Style
my_str = f"{Fore.BLUE}Hello, {Style.RESET_ALL} guys. {Fore.RED} I should be red."
print(my_str)
This gives me:
As you can see Fore.<color name> changes the color of the text after it, until the Style.RESET_ALL. After that you can change the color of the text again.
There could be multiple ways to achieve this. One which doesn't require any extra packages is to use ANSI color codes. Look at this link. Below are some examples.
s = "\033[1;32;40m Bright Green on black \033[1;31;43m Red on yellow \033[1;34;42m Blue on green \033[1;37;40m"
print(s)
Here in first code \033[1;32;40m, \033[ is the escape code followed by 1 for bold, 32 for bright green text and 40 for black background. The 3 codes are separated by ; and ended with m. Adding all the 3 codes (1, 32 and 40 here) isn't mandatory though.
output:
Other ways to achieve this can be found here.

How to get matching colors (red and green) for a given color code (blue)

I am new to CSS and programming in general so I am sorry if this is a beginner question but I couldn't find a proper solution myself.
If I have a certain color code (HEX), e.g. #028dca, how can I get matching colors for this ?
I found a number of tools online but I only saw solutions that give me different shades of the same color whereas I need different colors that match the above hue etc., especially red and green - and a few more colors would be nice to have.
One of several examples I tested is the following but again I couldn't find a proper red and green tone there, just different shades of blue and orange as the complementary color (and it looked similar with other tools I checked): https://color.adobe.com
Can someone help me with this ?
Many thanks in advance,
Mike
Don't know actually what you mean with "couldn't find a proper red and green tone". Given a particular color, it has complementary colors... it's math.
Here is the one that I use: http://croma.numixproject.org
Try using Coolors.co
You can fix on colors and then try different palettes.
The one with the color you posted would be like this - http://coolors.co/app/86615c-f1a699-028dca-79065a-02241a.
You can explore more by hitting the spacebar

Fabric.js - text decoration looks not exactly right

This image is from kitchensink, and the problems are :
Line through doesn't exactly at right place (see the left text at top)
When it's italic with background color, the text is a bit out of its background (see the left text at top)
Underline is a bit far from text, or can we adjust its distance?
Thanks.
You're seeing an experimental feature — fabric.IText — that's currently in development. It allows to edit text inline and supports partial formatting.
The problem with line-through is known.
Underline being far probably has to do with stretched text. When I load kitchensink it looks good.
Background and italics is an interesting one. I just checked google docs and there's the same problem there:

wxpython textctrl change caret colour

I'm using a wxpython textctrl & would like to hide the caret. After a lot of searching it would appear that the best approach would be to simply change it's colour to white. However I can not work out how to do this.
I found the following info:
SetCaretForeground(fore)
Sets the foreground color of the caret. The parameter fore is a wxColour object, a #RRGGBB string, or a color spec like "white". Returns None.
from here: http://www.yellowbrain.com/stc/caret.html#setfg
The code for my current textctrl is below. Any help would be appreciated.
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL)
Clinton.
You are using a wx.TextCtrl and the link you give is for a wx.StyledTextCtrl. These are completely different animals, and the wx.StyledTextCtrl has a lot more functionality than the simple wx.TextCtrl.
I don't think there's a way to set the caret color in an ordinary wx.TextCtrl.

Resources