Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing corner squares with automatic scaling #21

Closed
mattdm opened this issue Jul 27, 2021 · 3 comments
Closed

missing corner squares with automatic scaling #21

mattdm opened this issue Jul 27, 2021 · 3 comments

Comments

@mattdm
Copy link

mattdm commented Jul 27, 2021

I'm making 50×20 grids, so each block is 0.1%. I've found that with some data, the top right corner ends up empty. Here's a real-world example:

#!/usr/bin/python3

import matplotlib as m
m.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.dates as dates
from pywaffle import Waffle

m.style.use('seaborn-whitegrid')
m.rcParams['font.size'] = 12

fig = plt.figure( 
FigureClass=Waffle, 
 rows=20,
 columns=50,
 values={'32': 192,'33': 76,'34':59},
 figsize=[16, 9],
)              

fig.savefig('test.png',dpi=300)

            
plt.close()   

This results in:

test

... with an empty square in the top right -- a total of 999 squares instead of 1000.

I assume this is because all values are getting rounded down.

@gyli
Copy link
Owner

gyli commented Jul 27, 2021

You are right, the numbers are rounded.

Two options here:

  1. Adding a new category like "Others" or something, to make sure the sum of all values 1000 or any multiples of 1000
  2. Adding rounding_rule='ceil' when calling figure. Here are more details https://pywaffle.readthedocs.io/en/latest/examples/value_scaling_and_auto_sizing.html?highlight=rounding_rule

@mattdm
Copy link
Author

mattdm commented Jul 27, 2021

Ah, perfect. rounding_rule='ceil' is perfect for my purposes. Thanks!

@mattdm mattdm closed this as completed Jul 27, 2021
@mattdm
Copy link
Author

mattdm commented Jul 27, 2021

Result, for completeness:

test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants