The figure is not fully displayed

The figure is not fully displayed. When I was conducting the Visualize Label Distribution experiment(Visualize Label Distribution - Flower Datasets 0.5.0), I found that the final result’s graph was not fully displayed. Why?
Here is my code and the result of running it on pycharm.

from flwr_datasets import FederatedDataset
from flwr_datasets.partitioner import DirichletPartitioner
from flwr_datasets.visualization import plot_label_distributions

fds = FederatedDataset(
    dataset='cifar10',
    cache_dir='./Datasets',
    partitioners={
        'train': DirichletPartitioner(
            num_partitions=10,
            partition_by='label',
            alpha=0.3,
            seed=42,
            min_partition_size=0,
        ),
    },
)

partitioner = fds.partitioners['train']
fig, ax, df = plot_label_distributions(
    partitioner,
    label_name='label',
    plot_type='bar',
    size_unit='absolute',
    partition_id_axis='x',
    legend=True,
    title="Per Partition Label Distribution",
    verbose_labels=True,
)
fig.show()
fig.savefig('label_distribution.png')
2 Likes

Hello @harrow, you’ll need to slightly tweak your fig.savefig() line like this:

fig.savefig('label_distribution.png', bbox_inches="tight")

In this way, the entire figure as displayed with the fig.show() will be saved to disk. Does it work for you?

2 Likes

It was indeed worked. Thank you!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.