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

is it possible to control edge color? #37

Open
JosephBARBIERDARNAL opened this issue Jul 16, 2024 · 5 comments
Open

is it possible to control edge color? #37

JosephBARBIERDARNAL opened this issue Jul 16, 2024 · 5 comments

Comments

@JosephBARBIERDARNAL
Copy link

Hello!

Is there a way to control the border of each block? Because if there isn't, I get the impression that it's not possible to create dark, satisfying graphics with pywaffle.

Here is an example (and its output):

import matplotlib.pyplot as plt
import pandas as pd
from pywaffle import Waffle

path = 'https://raw.githubusercontent.com/holtzy/R-graph-gallery/master/DATA/share-cereals.csv'
df = pd.read_csv(path)

def remove_html_tag(s):
    return s.split('</b>')[0][3:]

df['lab'] = df['lab'].apply(remove_html_tag)
df = df[df['type'] == 'feed']

background_color = "#222725"
pink = "#f72585"
black = "#4F0325"

number_of_bars = len(df)  # one bar per continent

# Init the whole figure and axes
fig, axs = plt.subplots(
   nrows=number_of_bars,
   ncols=1,
   figsize=(8, 6)
)
fig.set_facecolor(background_color)
ax.set_facecolor(background_color)


# Iterate over each bar and create it
for (i, row), ax in zip(df.iterrows(), axs):

    share = row['percent']
    values = [share, 100-share]

    Waffle.make_waffle(
        ax=ax,
        rows=4,
        columns=25,
        values=values,
        colors=[pink, black],
        edgecolor='white'
    )

plt.show()
Screenshot 2024-07-16 at 14 25 50
@JosephBARBIERDARNAL
Copy link
Author

I'd like to be able to make something like:

Screenshot 2024-07-16 at 14 29 46

@gyli
Copy link
Owner

gyli commented Jul 17, 2024

Hi @JosephBARBIERDARNAL! I think that's a nice to have feature, let me see if and how it can be aded.

@JosephBARBIERDARNAL
Copy link
Author

cool! I'm ready to help if you need it

@gyli
Copy link
Owner

gyli commented Jul 19, 2024

PR is surely welcomed!
While before starting coding, I think it's discussable how to achieve this.
At my first glance, I thought we just need to add 4 edges outside of each block. But what would be the default line weight? Seems like the screenshot you attached is a special case, that edges happen to fill the gaps, and I think we can make this as the default option.
Then, how can we make the edge weight adjustable? So I can have block with edge and gap at the same time? Probably we can make a new parameter like edge_ratio (the ratio of edge width and gap width), similar to how to control gap size with interval_ratio_x and interval_ratio_y.
Also, the block might not always be a square, and I don't have a good solution to add beautiful edges in this case. Probably we can skip this case.

@JosephBARBIERDARNAL
Copy link
Author

Hello again!

My first intuition is as follows

  • let's start by having a simple way of filling in the edge colors (similar to my example above)
  • the default colour would be the background color of the axes (which is currently the case)?
  • This means that regardless of the shape of the blocks or the space between them, all the empty spaces between the blocks will be filled

then, depending on the usefulness you see in it, a way of controlling the weight of the edges (which means leaving partially empty spaces?)

but IMO the main use case would be to fill the spaces using a given color. Since I haven't looked at the source code yet, I don't measure how complex is it to implement?

Note: I'm don't have much free time at the time I'm writing this, but I will have much more from September (:

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