microsoft / vscode-jupyter

VS Code Jupyter extension
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
MIT License
1.3k stars 293 forks source link

Feature request - default themes for Python interactive window #3725

Closed PierreMarchand20 closed 3 years ago

PierreMarchand20 commented 5 years ago

Consider the possibly to change the style of the Python Interactive window, especially when using jupyter, and providing a list of default themes, a style "JupyterLab" would be nice for example.

It would allow us to enhance the results, like Markdown Preview Enhanced enhances the markdown output (and provides a list of default themes) or VS Code Jupyter Notebook Previewer enhances its own window viewer.

PierreMarchand20 commented 5 years ago

An example: I like the solarized dark theme but it gives me the following highlighting image image which is not really readable (especially the blue for functions and black for operations). Strangely enough, it is different from my python highlighting image At least, it would be nice to have the same colors as in the '.py' file.

rchiodo commented 5 years ago

We have an outstanding issue (#3107) to fix up the colors for the python in the interactive window.

Are you asking for more than just matching the python colors? Did you want theming for graphs and such too?

PierreMarchand20 commented 5 years ago

Oh Well I do not know, a good start would be to have the same syntax coloring as in the editor. Because the python parts of the interactive window really hurt the eyes.

But then, it would be nice to have the option to have something like https://github.com/jithurjacob/vscode-nbpreviewer or the Jupiter lab, with a white background. Because for example, if I want to show something "live", it would be more readable.

stevenlis commented 5 years ago

I have the same issue. The jupyter window is much more readable if I change the theme to Light. So I wonder if it is possible to set different themes for those two separate windows.

snipaste_457 snipaste_534

stevenlis commented 5 years ago

a new issue was opened for this request by @IanMatthewHuff.

stevenlis commented 5 years ago

@PierreMarchand20 In the meantime: https://github.com/neuron-team/vscode-ipe

PierreMarchand20 commented 5 years ago

Thx ! I know this one also: https://marketplace.visualstudio.com/items?itemName=donjayamanne.jupyter

PierreMarchand20 commented 5 years ago

But I guess that at the end, the goal is to have all these features in vscode-python

stevenlis commented 5 years ago

@PierreMarchand20 indeed...

stevenlis commented 5 years ago

@rchiodo The version 2019.1.0 somehow converts the tick label to white in fivethirtyeight theme. Is this expected? image

rchiodo commented 5 years ago

Yes that's expected. You have to do this instead (as we are applying a dark background to matplotlib when the theme is dark):

#%%
with plt.style.context('fivethirtyeight', True):
    fix, ax = plt.subplots()

Without the after_reset style argument, I get this:

image

With after_reset set to True, I get this: image

stevenlis commented 5 years ago

How should I specify this if I use plt.use.style()?

rchiodo commented 5 years ago

You'd put that command before your plot. Like so:

plt.style.use('fivethirtyeight')
fix, ax = plt.subplots()

This goes into more detail: https://matplotlib.org/users/style_sheets.html

Essentially imagine we have a plt.style.use('dark_background') at the very top of your file (because that's what we do when you startup with a dark scheme)

If you want to override just parts of it, this works:

plt.style.use(['fivethirtyeight', 'dark_background'])
fix, ax = plt.subplots()

I end up with this result then: image

stevenlis commented 5 years ago

Thanks for the information man... I just want the text labels to be black and eventually end up using:

plt.style.use(['seaborn', 'fivethirtyeight'])
stefandeml commented 5 years ago

+1 to fix this issue

currently the interactive window is really hard to be used with dark themes

rchiodo commented 5 years ago

@stefandeml what theme are you currently using? Some of the dark themes we aren't finding the colors for, but it should work for the default dark theme.

rchiodo commented 5 years ago

I should also add, it's unlikely we'll be adding 'custom' jupyter themes anytime soon. We're going to make the vscode themes all work with our window, but I don't see us adding our own set of colors.

tku137 commented 5 years ago

@rchiodo can confirm that the default dark theme works, but nothing else. For example, I am using this: https://marketplace.visualstudio.com/items?itemName=zhuangtongfa.Material-theme

clamydo commented 5 years ago

The issue with changing the style is that is also reflected in exported figures.

Example code:

#%%
import matplotlib.pyplot as plt
import numpy as np

#%%
%matplotlib inline

#%%
x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)

fig, ax = plt.subplots()
ax.plot(x, y)

fig.savefig('plot.png')

If exexuted with, for example, the Dark theme the PNG also will have a dark themed plot. This might not be what you would expect!

PierreMarchand20 commented 5 years ago

Without adding several themes for the jupyter window, just one similar to jupyter lab would be nice. Or at least a simple one with a white background and written black. This would make us able to export figures with a more neutral style.

rchiodo commented 5 years ago

One potential idea would be for us to ship a vscode theme with special scopes.

Right now a vscode theme has json like so for different colors:

"name": "Abyss",
    "tokenColors": [
        {
            "settings": {
                "background": "#000c18",
                "foreground": "#6688cc"
            }
        },
        {
            "scope": ["meta.embedded", "source.groovy.embedded"],
            "settings": {
                "background": "#000c18",
                "foreground": "#6688cc"
            }
        },

We could add a theme like this with special scopes that we use just in our jupyter output. Something like:

"name": "Python Interactive",
    "tokenColors": [
        {
            "scope": ["matplotlib.background", ],
            "settings": {
                "background": "#FFFFFF",
            }
        },

Once we did that other people could make interactive themes based on other themes. (A theme can include other theme's json too)

KenanHArik commented 5 years ago

+1 for fixing on dark themes. Was really excited about the new interactive console... but what a shock when I saw the colors:

Compare the functions above and below!

image

I'm currently using Material Theme: Palenight High Contrast. VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=Equinusocio.vsc-material-theme

We're going to make the vscode themes all work with our window, but I don't see us adding our own set of colors.

Looking forward to those additions @rchiodo !

rchiodo commented 5 years ago

@KenanHArik that theme should be working now. At least it does in our insiders build.

image

Although make sure to reload VS code after installing. The 'Python Interactive' window isn't capable of updating themes while it's open.

benc-uk commented 5 years ago

Using a dark theme here (Palenight) and a lot of the colours in the interactive view are unreadable :( It also seems to be ignoring my font settings

I'm on 1.32.1 and I just installed the insiders build of the extension

image

rchiodo commented 5 years ago

What does regular code look like? There's a known issue (#3175) with exception messages. Those colors are created by jupyter and not us. We need to just change the background on exceptions so that the jupyter colors work.

rchiodo commented 5 years ago

Actually fixing microsoft/vscode-python#3175 is trivial. I'm going to add a setting to specify the background color for error messages and default it to white.

rchiodo commented 5 years ago

See microsoft/vscode-python#4683 for the fix. That should make 'Palenight' work.

rchiodo commented 5 years ago

Font settings should work, but you need to restart the Python Interactive window.

rchiodo commented 5 years ago

@benc-uk the next insiders build should be able to show errors in dark themes:

image

You can set the background color for errors with "errorBackgroundColor". It defaults to white.

benc-uk commented 5 years ago

Great, thanks!

rchiodo commented 5 years ago

Uggh, just noticed the foreground color for normal text is still using the theme color. I'll update that too to based it off of the background color you set.

KenanHArik commented 5 years ago

@KenanHArik that theme should be working now. At least it does in our insiders build.

image

Although make sure to reload VS code after installing. The 'Python Interactive' window isn't capable of updating themes while it's open.

Thank you @rchiodo, just confirmed this is working on the insiders release. FYI The colors are not 100% match to my theme, but they work well on the palenight background.

Is there a rough timeline on when this may roll into the general extension release?

rchiodo commented 5 years ago

Should be in the next release. We release every 4 weeks now, so in a couple of weeks.

stefandeml commented 5 years ago

Fantastic! I can confirm that it now works as expected.

seanv507 commented 5 years ago

Sorry I am a bit lost in the comments. So I have problems with errors (eg dark blue against black) in version 1.32.3.
Screenshot from 2019-03-21 16-20-13_crop so I should use insiders build for the next week?

rchiodo commented 5 years ago

Yes insiders build of the python extension has the fix. We haven't officially shipped it yet.

stefandeml commented 5 years ago

Any blocker which prevents you from shipping this fix?

Rich Chiodo notifications@github.com schrieb am Do. 21. März 2019 um 16:24:

Yes insiders build of the python extension has the fix. We haven't officially shipped it yet.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode-python/issues/3773#issuecomment-475274904, or mute the thread https://github.com/notifications/unsubscribe-auth/AInEg9Eu9xONoGvKMlQ9qlH4Twa_1Zt1ks5vY6QogaJpZM4ZdqEJ .

--

Stefan Deml

  • 41 76 665 60 55
rchiodo commented 5 years ago

@stefandeml no, there is nothing blocking this. We'll ship it officially next week.

If you want it now, you can install the insider's build.

Download the vsix from the link and run the 'Install From VSIX' command in VS code.

stefandeml commented 5 years ago

Yeah, I've it working already. However it seems to bother a couple of users hence shipping the update would be awesome.

Rich Chiodo notifications@github.com schrieb am Do. 21. März 2019 um 18:35:

@stefandeml https://github.com/stefandeml no, there is nothing blocking this. We'll ship it officially next week.

If you want it now, you can install the insider's build https://pvsc.blob.core.windows.net/extension-builds/ms-python-insiders.vsix .

Download the vsix from the link and run the 'Install From VSIX' command in VS code.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode-python/issues/3773#issuecomment-475330572, or mute the thread https://github.com/notifications/unsubscribe-auth/AInEg4nTfOCk-DFlMGOhDZxTdj_8TC-pks5vY8LrgaJpZM4ZdqEJ .

--

Stefan Deml

  • 41 76 665 60 55
PierreMarchand20 commented 5 years ago

To give the examples I had first given at the beginning of this thread:

image image

It is almost as great as the highlighting of python code (the operator * is missing but it is not a big deal) and it is way more readable. But now there is an issue with error messages, they have a white background which makes them a bit weird in a dark theme:

image
rchiodo commented 5 years ago

Yeah our tokenization of the python code isn't exactly the same as VS Code. They don't expose their tokenizer and us implementing the same one would take a long time (and add some native dependencies that we didn't want). So we went with a 'close-enough' solution.

The error messages switching to white is another workaround. Jupyter colorizes the error messages using ansi escape codes. We didn't want to spend the time translating them for every theme, so forcing the background to white makes them match what Jupyter does.

stevenlis commented 5 years ago

@rchiodo the code indeed looks much better than before!

But I wonder if it is possible to add a setting to let the user pick a background color for the error messages to match their theme? or maybe use another color than pure white? The white color really has a very high contrast on a dark theme. 😢

rchiodo commented 5 years ago

@StevenLi-DS Actually there is :)

image

That setting I have there does this:

image

You'll have to play around with it to get something that still lets you read the text of the error message.

Here's what #444444 produces:

image

stevenlis commented 5 years ago

@rchiodo #444444 accidentally matches with my theme perfectly. Thanks!!!

image

JSON code:

{"python.dataScience.errorBackgroundColor": "#44444444"}

https://github.com/Microsoft/vscode-python/issues/3175

Mathenym commented 5 years ago

Got lost in the comments, but is there a way to leave the python interactive window in a light mode, and everything else in dark? For example, I am running into this rendering issue with the default dark theme. It would be nice to be able to see the syles that I set, as I use lots of plots for papes and such.

Screen Shot 2019-04-25 at 1 28 56 PM
rchiodo commented 5 years ago

There's supposed to be but it looks like our latest update broke it. :(.

It's this setting here:

image

I'll enter a new bug for it.

rchiodo commented 5 years ago

Here's the new bug. Hopefully we'll have an insider's build fix for this shortly.

https://github.com/Microsoft/vscode-python/issues/5480

stevenlis commented 5 years ago

@rchiodo It seems more like a facecolor issue to me and users just need to set it to white since many themes use transparent facecolor.

Mathenym commented 5 years ago

@StevenLi-DS How do you set the facecolor? I don't see it in the .json file for the theme that is applied. Or do you mean set the facecolor for every plot?

stevenlis commented 5 years ago

which style are you using? I believe you can set it globally. e.g.

sns.set_style(rc={'figure.facecolor':'white'})

image