Skip to content

Commit e40ae84

Browse files
In vscode default dark theme default the matplot lib style to dark_background (#3230)
* allow for matplotlib dark theme in vscode default dark theme * put back comment * check for any dark theme
1 parent e05a7c9 commit e40ae84

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/client/datascience/jupyterServer.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Observable } from 'rxjs/Observable';
1212
import * as uuid from 'uuid/v4';
1313
import * as vscode from 'vscode';
1414

15+
import { IWorkspaceService } from '../common/application/types';
1516
import { IFileSystem } from '../common/platform/types';
1617
import { IDisposableRegistry, ILogger } from '../common/types';
1718
import { createDeferred } from '../common/utils/async';
@@ -36,7 +37,8 @@ export class JupyterServer implements INotebookServer {
3637
@inject(INotebookProcess) private process: INotebookProcess,
3738
@inject(IFileSystem) private fileSystem: IFileSystem,
3839
@inject(IDisposableRegistry) private disposableRegistry: IDisposableRegistry,
39-
@inject(IJupyterExecution) private jupyterExecution : IJupyterExecution) {
40+
@inject(IJupyterExecution) private jupyterExecution : IJupyterExecution,
41+
@inject(IWorkspaceService) private workspaceService: IWorkspaceService) {
4042
}
4143

4244
public start = async () : Promise<boolean> => {
@@ -84,9 +86,18 @@ export class JupyterServer implements INotebookServer {
8486
// Wait for it to be ready
8587
await this.session.kernel.ready;
8688

87-
// Setup the default imports (this should be configurable in the future)
89+
// Check for dark theme, if so set matplot lib to use dark_background settings
90+
let darkTheme: boolean = false;
91+
const workbench = this.workspaceService.getConfiguration('workbench');
92+
if (workbench) {
93+
const theme = workbench.get<string>('colorTheme');
94+
if (theme) {
95+
darkTheme = /dark/i.test(theme);
96+
}
97+
}
98+
8899
this.executeSilently(
89-
'import pandas as pd\r\nimport numpy\r\n%matplotlib inline\r\nimport matplotlib.pyplot as plt'
100+
`import pandas as pd\r\nimport numpy\r\n%matplotlib inline\r\nimport matplotlib.pyplot as plt${darkTheme ? '\r\nfrom matplotlib import style\r\nstyle.use(\'dark_background\')' : ''}`
90101
).ignoreErrors();
91102

92103
return true;

0 commit comments

Comments
 (0)