def visualize(self, filename=None, tables_to_show=None):
        """Visualize databases and create an er-diagram

        Args:
            filename(str): filepath for saving the er-diagram
            tables_to_show(list): A list of tables to actually visualize.
                Tables not included in this list will not be visualized,
                but their foreign keys will be visualize if it refers to a
                table in this list
        """
        # Import pygraphviz for plotting the graphs
        try:
            import pygraphviz
        except __HOLE__:
            logger.error('Install pygraphviz for visualizing databases')
            raise

        if filename is None:
            raise DatabaseInputError(
                'Filename must be provided for visualization')

        logger.info('Creating a visualization of the database')
        graph = pygraphviz.AGraph(name='Database', label='Database')

        tables = [r for r in self.relations() if isinstance(r, Table)]
        if tables_to_show is None:
            tables_to_show = [table.full_name for table in tables]

        # Add nodes
        for table in tables:
            if table.full_name in tables_to_show:
                graph.add_node(table.full_name, shape='none',
                               label=self._make_node_label(table))

        # Add edges
        for table in tables:
            for cols, ref_table, ref_cols in table.foreign_key_references():
                if table.full_name in tables_to_show or \
                        ref_table in tables_to_show:
                    graph.add_edge(
                        ref_table,
                        table.full_name,
                        tailport=ref_cols[0],
                        headport=cols[0],
                        dir='both',
                        arrowhead='crow',
                        arrowtail='dot',
                    )

        # Plotting the graph with dot layout
        graph.layout(prog='dot')
        graph.draw(filename)
dataset/ETHPy150Open coursera/dataduct/dataduct/database/database.py/Database.visualize