Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC: Refactor code in the fishbone diagram example #28144

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

Merged
merged 1 commit into from
May 2, 2024

Conversation

saranti
Copy link
Contributor

@saranti saranti commented Apr 27, 2024

PR summary

  • Simplify the code in the cause and draw_body functions.
  • Remove the draw_spine code from draw_body and turn into its own function.
    • Fixed issue where the spine was being rendered multiple times due to being inside a loop.
  • Improve docstrings and comments.
  • Other minor changes.

@github-actions github-actions bot added the Documentation: examples files in galleries/examples label Apr 27, 2024
@saranti saranti force-pushed the refactor_fishbone branch 2 times, most recently from 0782ed6 to 47f9ae1 Compare April 27, 2024 06:18
@saranti saranti force-pushed the refactor_fishbone branch from 47f9ae1 to f748ddb Compare April 27, 2024 06:58

spine_length = [-2.1 - length, 2 + length]
head_pos = [2 + length, 0]
tail_pos = [[-2.8 - length, 0.8], [-2.8 - length, -0.8], [-2.0 - length, -0.01]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tail_pos = [[-2.8 - length, 0.8], [-2.8 - length, -0.8], [-2.0 - length, -0.01]]
tail_pos = [[-2.8 - length, 0.8], [-2.8 - length, -0.8], [-2.0 - length, -0.01]]
draw_spine(spine_length, head_pos, tail_pos)

Let's move drawing the spine up here, this is where all relevant input for the function is calculated. Also, it's the order , you would draw such a diagram by hand: first the spine, and then the problem categories.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may even be a good idea to pull all the positioning details in to the function, so that you do

draw_spine(-2 - length, 2 + length)

which gives the length of the line.

Note that the left of spine_length is -0.1 compared to that, which I assume is so that the line reaches into the tail triangle. Otherwise the transition may not look smooth. But that should be an implementation detail, i.e. (or so - untested)

def draw_spine(xmin, xmax):
    ...
    # draw main spine
    ax.plot([xmin-0.1, xmax], [0, 0], color='tab:blue', linewidth=2)
    # draw fish head
    ax.text(xmax + 0.1, - 0.05, 'PROBLEM', fontsize=10,
            weight='bold', color='white')
    semicircle = Wedge((xmax, 0), 1, 270, 90, fc='tab:blue')
    ax.add_patch(semicircle)
    # draw fishtail
    tail_pos = [[xmin - 0.8, 0.8], [xmin - 0.8, -0.8], [xmin, -0.01]]
    triangle = Polygon(tail, fc='tab:blue')
    ax.add_patch(triangle)

# the cause_arrow_x, cause_arrow_y coordinates.
causes(problem, cause_arrow_x, cause_arrow_y, top=top_row)
causes(problem, cause_arrow_x, cause_arrow_y, top=plot_above)
draw_spine(spine_length, head_pos, tail_pos)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
draw_spine(spine_length, head_pos, tail_pos)

@saranti saranti force-pushed the refactor_fishbone branch from f748ddb to f393a8e Compare May 1, 2024 06:50
@timhoffm timhoffm added this to the v3.9.1 milestone May 2, 2024
@timhoffm timhoffm merged commit e253aa2 into matplotlib:main May 2, 2024
22 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request May 2, 2024
timhoffm added a commit that referenced this pull request May 2, 2024
…144-on-v3.9.x

Backport PR #28144 on branch v3.9.x (DOC: Refactor code in the fishbone diagram example)
@saranti saranti deleted the refactor_fishbone branch May 3, 2024 00:13
@QuLogic QuLogic modified the milestones: v3.9.1, v3.9.0 May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: examples files in galleries/examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants