1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] IPython / Jupyter: how to customize the display function

Discussão em 'Python' iniciado por Stack, Novembro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I have 3 basic problems when displaying things in IPython / JupyterLab.

    (1) I have a pandas dataframe with many columns. First, I make sure I can see a decent portion of it:

    import numpy as np
    import pandas as pd
    np.set_printoptions(linewidth=240,edgeitems=5,precision=3)
    pd.set_option('display.width',1800) #number of pixels of the output
    pd.set_option('display.max_columns',100) #replace the number with None to print all columns
    pd.set_option('display.max_rows',10) #max_columns/max_rows sets the maximum number of columns/rows displayed when a frame is pretty-printed
    pd.set_option('display.min_rows',9) #once max_rows is exceeded, min_rows determines how many rows are shown in the truncated representation
    pd.set_option('display.precision',3) #number of digits in the printed float number


    If I print it, everything gets mushed together:

    [​IMG]

    Is it possible to print text wide, i.e. in a way that each line (even if longer) is printed on only 1 line in output, with a slider when lines are wider than the window?

    (2) If I display the mentioned dataframe, it looks really nice (has a slider), but some string entries are displayed over 4 rows:

    [​IMG]

    How can I make sure every entry is displayed in 1 row?

    (3) The code below produces the output, which works fine:

    import numpy as np
    import matplotlib.pyplot as plt
    x=np.linspace(0.1,30,1000);
    fig,ax=plt.subplots(1, 4, constrained_layout=True, figsize=[15,2])
    ax=ax.ravel()
    ax[0].plot( x, np.sin(x))
    ax[1].plot( x, np.log(1+x))
    ax[2].plot( x, np.sin(30/x))
    ax[3].plot( x, np.sin(x)*np.sin(2*x))
    plt.show()


    [​IMG]

    However, when I change [15,2] to [35,2], the figure will only be as wide as the window. How can I achieve that larger widths produce a slider (like display of a dataframe) so that I can make images as wide as I wish?

    Continue reading...

Compartilhe esta Página