Skip to content

Float field required in order for any of this code to work on matplotlib. If float field not input, form dialog does not open.  #93

@amrambouskila

Description

@amrambouskila

from matplotlib.backend_tools import ToolBase
from matplotlib.backends.qt_editor._formlayout import fedit
import matplotlib.pyplot as plt
import matplotlib
import pandas as pd
import os

class Save(ToolBase):

default_keymap = 'X'
description = 'Save dataframe to csv, xlsx, json, ubin, or hdf'
image = ''
df = pd.read_csv('C:\Python\PY3810_64v1\Lib\site-packages\\data\sample.csv')

def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

def trigger(self, *args):
    datalist = [('File Type', ['', '', 'xlsx', 'csv', 'json', 'ubin', 'hdf']),
                     ('', 0.0), # if this line is commented out, the code stops working with matplotlib plot --- this is where the issue lies
                    ('File Path', os.getcwd())]

    def apply_callback(data):
        (file, path) = data
        if file == 'csv':
                Save.df.to_csv('path')

    fedit(datalist, 'Excel', 'Save the current dataframe', parent=None, apply=apply_callback)

matplotlib.use('Qt5Agg', force=True)
plt.rcParams['toolbar'] = 'toolmanager'
fig, ax = plt.subplots()
fig.canvas.manager.toolmanager.add_tool('Save', Save)
fig.canvas.manager.toolbar.add_tool('Save', 1, -1)
plt.show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions