Esempio n. 1
0
def export_data_if_needed(df, props):
    def get_prop(k):
        return props[k] if k in props else None

    def printer(arr):
        return np.array_str(arr)

    if _parse_optional_bool(get_prop("export_data")):
        format = "csv"
        folder = get_prop("image_export_folder") or os.getcwd()
        filename = get_prop("image_export_filename") or _sanitize_filename(
            chart.get_name())
        filepath = os.path.join(folder,
                                filename) + "." + format  #TODO make it better

        print("exporting data to: '" + filepath + "' as " + format)

        old_opts = np.get_printoptions()
        np.set_printoptions(threshold=np.inf, linewidth=np.inf)
        np.set_string_function(printer, False)
        pd.set_option('display.max_columns', None)
        pd.set_option('display.max_colwidth', None)
        df.to_csv(filepath)
        np.set_string_function(None, False)
        np.set_printoptions(**old_opts)
Esempio n. 2
0
def export_image_if_needed(props):
    def get_prop(k):
        return props[k] if k in props else None

    if _parse_optional_bool(get_prop("export_image")):
        format = get_prop("image_export_format") or "svg"
        folder = get_prop("image_export_folder") or os.getcwd()
        filename = get_prop("image_export_filename") or _sanitize_filename(chart.get_name())
        filepath = os.path.join(folder, filename) + "." + format #TODO make it better
        width = float(get_prop("image_export_width") or 6)
        height = float(get_prop("image_export_height") or 4)
        dpi = get_prop("image_export_dpi") or "96"

        print("exporting image to: '" + filepath + "' as " + format)

        plt.gcf().set_size_inches(width, height)
        plt.savefig(filepath, format=format, dpi=int(dpi))