diff --git a/compressed_sensing.ipynb b/compressed_sensing.ipynb index 4035d07f360cc2493558c3f9e0ee90bec1e5ac15..45ce779463b903b947310fcdb289b35427aa39c7 100644 --- a/compressed_sensing.ipynb +++ b/compressed_sensing.ipynb @@ -123,7 +123,7 @@ "from compressed_sensing.scatter_plot import show_scatter_plot\n", "from compressed_sensing.visualizer import Visualizer\n", "# set display options for the notebook \n", - "%matplotlib inline\n", + "# %matplotlib inline\n", "warnings.filterwarnings('ignore')" ] }, @@ -664,6 +664,26 @@ "Note the size of the feature space, the needed time to run the code and the accuracy (using the default settings)!" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "# import tkinter as tk\n", + "# import tkinter.ttk as ttk\n", + "# from tkcolorpicker import askcolor\n", + "\n", + "# root = tk.Tk()\n", + "# style = ttk.Style(root)\n", + "# style.theme_use('clam')\n", + "\n", + "# print(askcolor((255, 255, 0), root))\n", + "# root.mainloop()" + ] + }, { "cell_type": "code", "execution_count": null, @@ -750,6 +770,38 @@ "The markers represent the compounds and their colors the reference energy differences. How well does the descriptor separate the compounds with respect to their crystal structure?" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# from ttkwidgets.color import askcolor\n", + "# import tkinter as tk\n", + "# from tkinter import ttk\n", + "# from PIL import Image, ImageTk\n", + "\n", + "\n", + "# def pick(alpha=False):\n", + "# global im # to avoid garbage collection of image\n", + "# res = askcolor('sky blue', parent=window, title='Pick a color', alpha=alpha)\n", + "# canvas.delete('image')\n", + "# if res[1] is not None:\n", + "# im = ImageTk.PhotoImage(Image.new('RGBA', (100, 100), res[1]), master=window)\n", + "# canvas.create_image(60, 60, image=im, tags='image', anchor='center')\n", + "# print(res)\n", + "\n", + "\n", + "# window = tk.Tk()\n", + "# canvas = tk.Canvas(window, width=120, height=120)\n", + "# canvas.create_text(60, 60, text='Background', anchor='center')\n", + "# canvas.pack()\n", + "# ttk.Button(window, text=\"Pick a color (No alpha channel)\", command=pick).pack(fill='x')\n", + "# ttk.Button(window, text=\"Pick a color (With alpha channel)\", command=lambda: pick(True)).pack(fill='x')\n", + "# window.mainloop()" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/compressed_sensing/visualizer.py b/compressed_sensing/visualizer.py index 43a4cb9866792e5811b6bf91c6c1e9d3e697569a..fc82dbe7c0ec08d3f4a363b2090fd3c608bfbe50 100644 --- a/compressed_sensing/visualizer.py +++ b/compressed_sensing/visualizer.py @@ -2,6 +2,17 @@ import plotly.graph_objects as go import ipywidgets as widgets from jupyter_jsmol import JsmolView import numpy as np +from IPython.display import display, HTML +import os + +def javascript(*st,file=None): + if len(st) == 1 and file is None: + s = st[0] + elif len(st) == 0 and file is not None: + s = open(file).read() + else: + raise ValueError('Pass either a string or file=.') + display(HTML("<script type='text/javascript'>" + s + "</script>")) class Visualizer: @@ -110,7 +121,7 @@ class Visualizer: x=self.line_x, y=self.line_y, line=dict(color='Grey', width=1, dash=self.line_styles[0]), - name='Classification line', + name=r'Classification' + '<br>' + 'line', ) ) ) @@ -557,7 +568,13 @@ class Visualizer: def print_button_clicked(self, button): - self.fig.write_image(self.widg_plot_name.value + '.' + self.widg_plot_format.value, scale=self.widg_scale.value) + try: + os.mkdir("./plots") + except: + pass + file_name = self.widg_plot_name.value + '.' + self.widg_plot_format.value + self.fig.write_image("./plots/" + file_name, scale=self.widg_scale.value) + javascript("window.open('./plots/" + str(file_name) + "' )") def reset_button_clicked(self, button):