8000 Add custom_bar_plot() function by Saunakghosh10 · Pull Request #26310 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add custom_bar_plot() function #26310

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000 27 changes: 27 additions & 0 deletions galleries/plot_types/3D/custom_bar_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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)))

plt.bar(x, values, color=colors)
plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Custom Bar Plot')
plt.xticks(x, labels)
plt.grid(True)
plt.show()
28 changes: 14 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
# NOTE: This file must remain Python 2 compatible for the foreseeable future,
# to ensure that we error out properly for people with outdated setuptools
# and/or pip.
from setupext import print_raw, print_status
import setupext
import setuptools.command.sdist
import setuptools.command.build_py
import setuptools.command.build_ext
from setuptools import setup, find_namespace_packages, Distribution, Extension
import subprocess
import shutil
from pathlib import Path
import os
import sys

py_min_version = (3, 9) # minimal supported python version
Expand All @@ -24,22 +34,10 @@
'.'.join(str(n) for n in sys.version_info[:3]))
sys.exit(error)

import os
from pathlib import Path
import shutil
import subprocess

from setuptools import setup, find_namespace_packages, Distribution, Extension
import setuptools.command.build_ext
import setuptools.command.build_py
import setuptools.command.sdist

# sys.path modified to find setupext.py during pyproject.toml builds.
sys.path.append(str(Path(__file__).resolve().parent))

import setupext
from setupext import print_raw, print_status


# These are the packages in the order we want to display them.
mpl_packages = [
Expand All @@ -50,7 +48,7 @@
setupext.Qhull(),
setupext.Tests(),
setupext.BackendMacOSX(),
]
]


# From https://bugs.python.org/issue26689
Expand Down Expand Up @@ -236,6 +234,7 @@ def make_release_tree(self, base_dir, files):
update_matplotlibrc(
Path(base_dir, "lib/matplotlib/mpl-data/matplotlibrc"))


# Start with type hint data
# Will be further filled below by the various components.
package_data = {"matplotlib": ["py.typed", "**/*.pyi"]}
Expand Down Expand Up @@ -311,7 +310,8 @@ def make_release_tree(self, base_dir, files):
package_dir={"": "lib"},
packages=find_namespace_packages(
where="lib",
exclude=["*baseline_images*", "*tinypages*", "*mpl-data*", "*web_backend*"],
exclude=["*baseline_images*", "*tinypages*",
"*mpl-data*", "*web_backend*"],
),
py_modules=["pylab"],
# Dummy extension to trigger build_ext, which will swap it out with
Expand Down
0