Saving lattice visualization to a file
EgorDudyrev opened this issue · comments
Hello!
I'm trying to improve my FCA libraries performance benchmark (https://github.com/EgorDudyrev/FCApy/tree/feature/benchmarking/notebooks/Performance_Benchmark). But I have some problems saving concepts
lattice visualization to a file.
I use the function context.lattice.graphviz('concepts', render=True, )
to save a visualization into a file 'concepts.pdf'. It works for a small context (like 'animal_movement'). But when applied to 'Bob Ross elements-by-episode' dataset it results in a very wide and totally white pdf file.
What is the proper way to save (big) lattice visualization to a file? Can it be png file instead of pdf?
The code to reproduce the error:
import concepts import pandas as pd fname = 'bob_ross.csv' !wget -O {fname} -q https://raw.githubusercontent.com/fivethirtyeight/data/master/bob-ross/elements-by-episode.csv df = pd.read_csv(fname) df['EPISODE_TITLE'] = df['EPISODE']+' '+df['TITLE'] df = df.drop(['EPISODE','TITLE'],1).set_index('EPISODE_TITLE').astype(bool) context = concepts.Context(df.index, df.columns, df.values) context.lattice.graphviz('concepts', render=True, );
Upd. Seems like the problem is with the pdf viewer installed in my laptop.
I open the file with https://smallpdf.com/pdf-reader and after zooming in 26 times it finally shows a lattice.
Still, can a lattice visualization be saved to png file instead of pdf?
Hi Egor, yep, the issue is probably purely the size.
Still, can a lattice visualization be saved to png file instead of pdf?
Use the format
argument, see Lattice.graphviz() and Digraph.render()
AFAICT your code includes the row number as feature (68 instead of 67), here is an adaped version:
import pathlib
import concepts
import pandas as pd
URL = ('https://raw.githubusercontent.com/fivethirtyeight/data/master'
'/bob-ross/elements-by-episode.csv')
CSV = pathlib.Path('bob_ross.csv')
FORMAT = {'encoding': 'utf-8'}
if not CSV.exists():
pd.read_csv(URL, **FORMAT).to_csv(CSV, **FORMAT)
df = pd.read_csv(CSV, **FORMAT).drop('Unnamed: 0', axis='columns')
df['EPISODE_TITLE'] = df['EPISODE'] + ' ' + df['TITLE']
df = df.drop(['EPISODE','TITLE'], axis='columns')
df = df.set_index('EPISODE_TITLE', drop=True).astype(bool)
context = concepts.Context(df.index, df.columns, df.values)
assert len(context.objects) == 403
assert len(context.properties) == 67
dot = context.lattice.graphviz('bob_ross.gv', render=True, format='png')
Closing for now.