Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This commit introduces a custom bar plot function#26314

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

Saunakghosh10
Copy link

Commit

This commit introduces a custom bar plot function and provides an example of usage inside the code. The custom bar plot function allows users to create bar plots with customizable labels, values, and colours. It enhances the functionality of the code by providing a convenient way to visualize data.

Thecustom_bar_plot function takes in an array-like object oflabels representing the categories, an array-like object ofvalues representing the values for each category, and an optional array-like object ofcolours specifying the custom colours for each bar. If thecolours parameter is not provided, default colours from theViridis colourmap are used.

The example usage section demonstrates how to use thecustom_bar_plot function by creating a bar plot with sample data. Thelabels list contains the categories, thevalues list contains the corresponding values, and thecolours list specifies custom colours for each bar. Running the code will generate a bar plot with labelled categories, values, and a title.

This commit improves the code by adding a versatile function for custom bar plotting, enhancing the visualization capabilities and allowing users to tailor the appearance of their plots to their specific needs.

@rcomerrcomer mentioned this pull requestJul 15, 2023
5 tasks
@rcomer
Copy link
Member

Thank you for your contribution@Saunakghosh10!

Please could you revert the changes tosetup.py. They seem unrelated to the intent of this PR and I think they are causing all the failures in our automated checks below.

There are also several style issues highlighted by theflake8 checks. If these could be addressed, it will make it easier to review this in more detail. Seethe second bullet here for how to runflake8 checks locally.

@Saunakghosh10
Copy link
Author

okay thank you

@story645
Copy link
Member

story645 commentedJul 16, 2023
edited
Loading

Thanks for making this example! Can you please write it using ax. API to conform to our style guidelines?https://matplotlib.org/devdocs/devel/document.html#write-examples-and-tutorials

If you're not sure how, please ask here or in our chat.

Eta: also please revert the changes to 3D bar since there isn't anything especially related to 3D here.

@timhoffm
Copy link
Member

timhoffm commentedJul 16, 2023
edited
Loading

Thanks for the desire to improve our examples!

Please describe more clearly what the purpose is. As of now, I do not see the benefit of adding this

create bar plots with customizable labels, values, and colours.

is already provided by the builtinbar() function. The only new aspect is the possibility to use colors from a colormap. However,

  1. I'm not sure that this warrants a new example. It's basically an orthogonal concept and we generally try to avoid these combinations because they'd result in vast amouts of examples ("bars with colors from a colormap", "line plots with colors from a colormap", "boxplots with colors from a colormap", ...) which makes finding relevant information much more difficult.

  2. If there are good reasons to show this combination, I'd like to see a more practical example:
    a) The function essentially boils down to

    colors = plt.cm.viridis(np.linspace(0, 1, len(labels)))plt.bar(labels, values, colors=colors)

    with additional hard-coded x/ylabels, title etc. This is not a function one could use in a real-world example. The above two lines are enough to demonstrate the concept of getting colors from a colormap.

    b) The reason for individual colors should be to encode additional information. Just encoding the sequence of bars (i.e. effectively overlaying the bar plot with a discretized color gradient) is thus not a good example. If we want to show this, we'd need a more real-world example where the coloring actually conveys additional information.

@rcomer
Copy link
Member

@timhoffm I haven't looked in detail, but I think this one is in response to@story645's suggestion at#26310.

@Saunakghosh10
Copy link
Author

Thanks for making this example! Can you please write it using ax. API to conform to our style guidelines?https://matplotlib.org/devdocs/devel/document.html#write-examples-and-tutorials

If you're not sure how, please ask here or in our chat.

Eta: also please revert the changes to 3D bar since there isn't anything especially related to 3D here.

import matplotlib.pyplot as plt
import numpy as np

def custom_bar_plot(labels, values, colors=None):
"""
Custom bar plot function that plots bars with optional custom colors.

Parameters:    labels (array-like): Labels for each bar.    values (array-like): Values for each bar.    colors (array-like, optional): Colors for each bar. If not provided, default colors are used.Returns:    None"""x = np.arange(len(labels))if colors is None:    colors = plt.cm.viridis(np.linspace(0, 1, len(labels)))fig, ax = plt.subplots()ax.bar(x, values, color=colors)ax.set_xlabel('Categories')ax.set_ylabel('Values')ax.set_title('Custom Bar Plot')ax.set_xticks(x)ax.set_xticklabels(labels)ax.grid(True)plt.show()

@story645
Copy link
Member

I'm not sure that this warrants a new example.

Agree, that's why I suggested it as a new section in the bar color demo.

@Saunakghosh10 great that it's now inax style. I agree w/@timhoffm that there isn't much utility in this being a function since the functionality you need is just what Tim shows. Can you pull this code out of a function and add some simple dummy data?

@Saunakghosh10
Copy link
Author

okay on it

@story645
Copy link
Member

Also, to revert the changes to setup.py and to the plot_gallery example, tryhttps://git-scm.com/docs/git-reset#Documentation/git-reset.txt-Resetasinglefileintheindex

@rcomer
Copy link
Member

@Saunakghosh10 are you still interested in working on this?

@Saunakghosh10
Copy link
Author

@Saunakghosh10 are you still interested in working on this?

yes I am and I and I am working on that only tbh..

@rcomer
Copy link
Member

rcomer commentedMay 11, 2024
edited
Loading

I'm going to mark this as "draft" for now. Please mark it as "ready for review" when you are ready. In the meantime, if you need help, feel free to ask questions here. Or you may prefer to ask them in ourincubator gitter room.

@rcomerrcomer marked this pull request as draftMay 11, 2024 14:57
@timhoffm
Copy link
Member

Closing because of the need for additional functionality is not clear.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
Status: Waiting for author
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@Saunakghosh10@rcomer@story645@timhoffm@jklymak

[8]ページ先頭

©2009-2025 Movatter.jp