python – Pandas styler object in Databricks loocks ugly

I am trying to make format a percentage column in pandas dataframe. Original dataframe, as outputted by Databricks

enter image description here

I want to format the color of the percentage column to depend on its contents. Also, the color depends on the index of the cell (iqr has other colour rules than HardDatefilter for instance). I did it with this piece of code (format subset is a list of columns we want to format, in this case format_subset=(‘percentage’). pdf is the dataframe.

cols = pdf.keys() if format_subset is None else format_subset
fmt = dict.fromkeys(cols,'{:.1%}')
pdf = pdf.style.format(fmt)

pdf.apply(lambda x: bg_mv_colors_vec(x, mv_relevance(x.name), dataset=dataset), axis=1 , subset=cols).apply(lambda x: fg_mv_colors_vec(x, mv_relevance(x.name),dataset=dataset), axis=1, subset=cols)

Here bg_mv_colors_vec and fg_mv_colors_vec determines the background and font color of each cell.
The output is as follows:

enter image description here

This looks super ugly, and I would like to see some borders or something.

I found the following related SO topic: Is there a quick way to turn a pandas DataFrame into a pretty HTML table?. However, this is not really a solution for my case. Databricks prints the dataframe nicely as long as it as normal dataframe, but when it is a styler object (which I need for the colorformatting) the databricks output is ugly.

plotting – Ugly streaks caused by Arg in a contour plot

I had a more general question about a similar problem more than two years ago, Getting rid of discontinuities in plots caused by square roots, logarithms, `Arg`, etc, which got lots of interesting feedback but no definite answer.

So I decided to focus on something more obviously urgent and simple.

Here is the result of

ContourPlot[Log[Abs[Sinh[Sinh[x+I y]]]],{x,-4,4},{y,-4,4},
 MeshFunctions->{Arg[Sinh[Sinh[#1+I #2]]]&},
 Mesh->11,PlotPoints->150,Contours->50]

enter image description here

I guess I don’t even need to ask: I want to get rid of those rough thick black lines, that’s all.

PS Heard rumours that it might be incorporated in version 12. I have 11.0.1.0, but still, let me know if this is the case.

Ugly text in shaded graphics

I’ve looked around but can’t find the solution to the following problem: Why is text so ugly in shaded graphics (ContourPlot, etc.)? Here’s an illustration:

data = RandomReal({0, 1}, {100, 2});
{Histogram(Flatten(data), PlotLabel -> Style("Label 12345", 20)),
 SmoothDensityHistogram(data, PlotLabel -> Style("Label 12345", 20))}

On my system (Mathematica 12.1, Windows 10) I get
enter image description here

All the text (tick and plot labels) is ugly. I’m not sure if it’s low-resolution, aliased, or antialiased the wrong way, but it’s just ugly.

Note that in Preferences, I’ve set Appearance/Graphics/Antialising quality to “highest.” I realize that can save the image using a high ImageResolution value. But is there any way I can nice-looking text in these kinds of graphics in my notebook?

Clarification: what I mean by “ugly” is the text in the right-hand graph. For comparison, the text in the left-hand graph looks much nicer (at least to me).

Thank you!

primes – Ugly or needed mixing of “C” and “C++” GNU MP

bool miller_rabin_base2_p(const mpz_class& number) {
  if (number == 2) return true;
  if (number < 2 || mpz_even_p(number.get_mpz_t())) return false;

  const mpz_class base(2), m(number - 1);
  mpz_class d, k, coset;

  k = mpz_remove(d.get_mpz_t(), m.get_mpz_t(), base.get_mpz_t());

  mpz_class exp(d);
  for (mpz_class i = 0; i < k; i++) {
    mpz_powm(coset.get_mpz_t(), base.get_mpz_t(), exp.get_mpz_t(),
             number.get_mpz_t());

    if (coset == 1 || coset + 1 == number) return true;
    exp <<= 1;
  }

  return false;
}

My function uses the Miller-Rabin primality test with base 2 to determine if the given number is probably prime. Since I wanted to test big numbers I used the mpz_class of the GNU MP library. But for some functions like mpz_powm() I didn’t find a “C++” like version. For that reason I had to use get_mpz_t() a lot, which looks kind of ugly.

So my questions is: Is that the recommended style for using gmpin C++? If not, what should be changed?

Google Sheet Scripts stops at large loop; the good, the bad and the ugly coding

I am learning Google Sheet Scripts. Please don’t burn me at the (blueray) stake >_<
The goal of my (over complicated) code is simple.

  • On the main sheet, Asteroids-Locations, I would like to type a value on column "F" Google Sheet: Asteroids-Locations
  • and have that value updated on the database sheet, New Eden Google Sheet: Asteroids-Locations

“Simple”…(while making a quotation hand gesture) right?…perhaps

The code works…up to a certain extent.

The database sheet, "New Eden", has 4,507 rows!!!
The code only can find up to 600’ish rows, anything after that the scripts times out and stops running. In other words, it can’t find all the database entries.

Here is the monster…it is…somewhat…alive…

//Set the environment
var map = {};
map.app = SpreadsheetApp;
//map.doc   = SpreadsheetApp.getActiveSpreadsheet(); //Active spreadseet
map.ui  = SpreadsheetApp.getUi(); //Alert function
map.data = {};

//Asteroids-Locations
map.sheet = map.app.getActiveSpreadsheet().getActiveSheet();
map.sheet.name = map.sheet.getName();
//map.cell  = map.sheet.getActiveCell();

map.data.row = map.sheet.getActiveCell().getRow();
map.data.sec = map.sheet.getRange("F" + map.data.row ).getValue();
map.data.system = map.sheet.getRange("D" + map.data.row ).getValue();

//New Eden
map.eden = {};
map.eden.sheet  = map.app.getActiveSpreadsheet().getSheetByName("New Eden");



//Data manipulation
function UpdateSec() {
    //Total Rows: 4507
    if( map.sheet.name == "Asteroids-Locations" && map.data.sec != "" ){
    for( row = 2; row <= 4507; row++ ){
        //row = 4507;
        var system = map.eden.sheet.getRange("C" + row ).getValue();

        if( system == map.data.system ){
        map.eden.sheet.getRange("D" + row ).setValue( map.data.sec ); //Update Database
        map.sheet.getRange("F" + map.data.row ).setValue( "" ); //Clear old value
        break; //Terminate  loop
        }
    } //end of loop

    msg( "Upate successful" );
    } //end of conditon
}



function msg(text) {
    map.ui.alert(text);
}

I’ll appreciate your help to make it work and change it into a good practice code.

Here is a copy of the file: https://docs.google.com/spreadsheets/d/1DJgcZC7wcA39gx_A7JM9A4I0dHF0lvB78pSxGMVYKrc/edit?usp=sharing

color management – switched to RAW and seeing ugly light bands in Lightroom

The first thing you must realize is that what you are seeing on your monitor is not “the” raw file. What you are seeing is an 8-bit demosaiced preview conversion of the raw file created by Photoshop (or whatever other raw conversion application you are using) based on the current settings. It’s just one of many possible interpretations of the full data in the raw image file. You may even be seeing the embedded jpeg preview in the raw file that was produced by the camera at the time you took the photo if that is what you have selected in the Photoshop preferences section!

How the data from the raw file is selectively rendered is partially determined by the choices you have made in Photoshop’s preferences section – both in the speed vs. quality rendering settings and in the default profile (WB, contrast, exposure, rtc.) applied to the raw file when it is opened. You can opt for faster but lower quality previews or for slower but higher quality previews.

If you then move some of the sliders the application reconverts the raw data based on the changes you made and displays the new 8-bit preview. With other adjustments the application will simply increase/decrease the value sent to the display. In both cases the application also keeps track of what settings you have selected, either via the initial profile you used to open the file or any changes you make after opening the file and saves them without altering the actual pixel data in the file.

When you export/convert the file based on the then-current settings the application will do the actual conversion and produce a new file in the output format you have selected: TIFF, PNG, JPEG, etc. Especially if you have Photoshop set up to convert the preview of an image on your screen more for speed than quality, what you see on the preview will not look the same as what you see when you actually convert the file.

Try actually converting the file to a high quality JPEG (same resolution as the original file and full color depth for the jpeg standard with minimal compression) and see if the resulting file shows the banding that you are seeing in the on-screen preview. If not, then look at your Photoshop preferences and change those “fast rendering” choices to “high quality”.

java – Ugly Number problem using dynamic programming

I am learning Dynamic Programming and tried to solve the nth ugly number problem using it. Here’s my code for the problem in Java:

import java.util.HashSet;

public class UglyNum {
    //using DP bottom up
    public static int getUgly(int n) {
        HashSet<Integer> u = new HashSet<>();
        if (n < 6)
            return n;
        for (int i = 1; i < 6; i++) {
            u.add(i);
        }
        int x = 5;
        int i = 6;
        boolean flag;
        while (x < n) {
            flag = false;
            flag = checkContains(i, 2, u, flag);
            if(!flag)
            flag = checkContains(i, 3, u, flag);
            if(!flag)
            flag = checkContains(i, 5, u, flag);
            if (flag) {
                u.add(i);
                x++;
            }
            if (x == n)
                return i;
            i++;
        }
        return -1;
    }


    private static boolean checkContains(int x, int n, HashSet<Integer> u, boolean flag) {
        if (x % n == 0) {
            if (u.contains(x / n))
                return true;
            else
                return false;
        }
        return flag;
    }
    //DP ends here

}

The idea is that a new number, say x, is ugly only if x/2 or x/3 or x/5 is ugly.

I analysed the code wrt the 2 codes given in the GFG site article and here are the results:
enter image description here

The first time (26.3992 ms) is the time using my dynamic programming approach. The other 2 are the ones given on the site. Clearly my program is taking too much time. Can you help me optimise it?

PS: I am aware of the awesome methods to solve the problem but wondering why mine is so slow.

Big Ugly Plymouth-Kubuntu 20.04

Plymouth screen worked fine before installing NVIDIA proprietary driver for GT 1030.
After installing proprietary driver, resolution is so bad.

I tried changing the resolution from GRUB CUSTOMIZER but it doesn’t work and i tried to include

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset"

this line doesn’t work too.

How to fix Plymouth screen after enabling NVIDIA drivers ?

Why this ugly looking formula to calculate ‘target’ from ‘nBits’ in block header: target = coefficient * 256**(exponent-3)

Why this ugly looking formula to calculate ‘target’ from ‘nBits’ in block header: target = coefficient * 256**(exponent-3).

enter image description here

Why not? : target = coefficient * 256**(exponent). What is the need of subtracting 3. All we need is to be able to generate 256 bit long number and enough precision (which we already have with 3 bytes dedicated for coefficient)

Even better, why not? : target = coefficient * 2**(exponent)