Skip to content

Commit 5789ccc

Browse files
authored
Merge pull request #135 from freethebee/hide_header
Hide header
2 parents ccf0876 + cc99d61 commit 5789ccc

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

examples/header_visible.ipynb

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"%matplotlib widget"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {
16+
"ExecuteTime": {
17+
"end_time": "2019-08-07T08:07:06.908562Z",
18+
"start_time": "2019-08-07T08:07:06.602919Z"
19+
}
20+
},
21+
"outputs": [],
22+
"source": [
23+
"import matplotlib.pyplot as plt"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": null,
29+
"metadata": {},
30+
"outputs": [],
31+
"source": [
32+
"fig, ax = plt.subplots()\n",
33+
"fig.canvas.layout.width = '7in'\n",
34+
"fig.canvas.layout.height= '5in'\n",
35+
"\n",
36+
"# if I hide the header here, I get a libpng error\n",
37+
"# fig.canvas.header_visible = False\n",
38+
"\n",
39+
"ax.plot([1,2,3], [4,5,3])"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": null,
45+
"metadata": {},
46+
"outputs": [],
47+
"source": [
48+
"# hiding after rendering works\n",
49+
"fig.canvas.header_visible = False"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": null,
55+
"metadata": {},
56+
"outputs": [],
57+
"source": [
58+
"# hiding together with calls to toolbar options, work.\n",
59+
"fig, ax = plt.subplots()\n",
60+
"fig.canvas.layout.width = '7in'\n",
61+
"fig.canvas.layout.height= '5in'\n",
62+
"\n",
63+
"fig.canvas.toolbar_visible = False\n",
64+
"fig.canvas.header_visible = False\n",
65+
"\n",
66+
"ax.plot([1,2,3], [4,5,3])"
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": null,
72+
"metadata": {},
73+
"outputs": [],
74+
"source": []
75+
}
76+
],
77+
"metadata": {
78+
"kernelspec": {
79+
"display_name": "Python 3",
80+
"language": "python",
81+
"name": "python3"
82+
},
83+
"language_info": {
84+
"codemirror_mode": {
85+
"name": "ipython",
86+
"version": 3
87+
},
88+
"file_extension": ".py",
89+
"mimetype": "text/x-python",
90+
"name": "python",
91+
"nbconvert_exporter": "python",
92+
"pygments_lexer": "ipython3",
93+
"version": "3.7.3"
94+
}
95+
},
96+
"nbformat": 4,
97+
"nbformat_minor": 2
98+
}

ipympl/backend_nbagg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ class Canvas(DOMWidget, FigureCanvasWebAggCore):
149149
toolbar = Instance(Toolbar, allow_none=True).tag(sync=True, **widget_serialization)
150150
toolbar_visible = Bool(True).tag(sync=True)
151151
toolbar_position = Enum(['top', 'bottom', 'left', 'right'], default_value='left').tag(sync=True)
152+
153+
header_visible = Bool(True).tag(sync=True)
154+
152155
_closed = Bool(True)
153156

154157
# Must declare the superclass private members.

js/src/mpl_widget.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var MPLCanvasModel = widgets.DOMWidgetModel.extend({
1616
_view_module: 'jupyter-matplotlib',
1717
_model_module_version: '^'+ version,
1818
_view_module_version: '^' + version,
19+
header_visible: true,
1920
toolbar: null,
2021
toolbar_visible: true,
2122
toolbar_position: 'horizontal'
@@ -62,6 +63,7 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
6263

6364
model_events: function() {
6465
this.model.on('msg:custom', this.on_comm_message.bind(this));
66+
this.model.on('change:header_visible', this.update_header_visible.bind(this));
6567
this.model.on('change:toolbar_visible', this.update_toolbar_visible.bind(this));
6668
this.model.on('change:toolbar_position', this.update_toolbar_position.bind(this));
6769
},
@@ -76,6 +78,11 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
7678
this.send_message('initialized');
7779
},
7880

81+
update_header_visible: function() {
82+
this.header.style.display = this.model.get('header_visible') ? '': 'none';
83+
this.request_resize();
84+
},
85+
7986
update_toolbar_visible: function() {
8087
this.toolbar_view.el.style.display = this.model.get('toolbar_visible') ? '' : 'none';
8188
this.request_resize();

0 commit comments

Comments
 (0)