diff --git a/galleries/examples/lines_bars_and_markers/bar_colors.py b/galleries/examples/lines_bars_and_markers/bar_colors.py index 35e7a64ef605..5320e750b9e8 100644 --- a/galleries/examples/lines_bars_and_markers/bar_colors.py +++ b/galleries/examples/lines_bars_and_markers/bar_colors.py @@ -8,6 +8,7 @@ Note that labels with a preceding underscore won't show up in the legend. """ +import numpy as np import matplotlib.pyplot as plt fig, ax = plt.subplots() @@ -24,3 +25,36 @@ ax.legend(title='Fruit color') plt.show() + + +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() + + +# Example usage +labels = ['Category 1', 'Category 2', 'Category 3', 'Category 4', 'Category 5'] +values = [15, 8, 12, 10, 5] +colors = ['red', 'blue', 'green', 'orange', 'purple'] + +custom_bar_plot(labels, values, colors) diff --git a/galleries/plot_types/3D/custom_bar_plot.py b/galleries/plot_types/3D/custom_bar_plot.py new file mode 100644 index 000000000000..b474b31a4941 --- /dev/null +++ b/galleries/plot_types/3D/custom_bar_plot.py @@ -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() diff --git a/setup.py b/setup.py index f58b30536aa3..699b1a97b3ec 100644 --- a/setup.py +++ b/setup.py @@ -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 @@ -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 = [ @@ -50,7 +48,7 @@ setupext.Qhull(), setupext.Tests(), setupext.BackendMacOSX(), - ] +] # From https://bugs.python.org/issue26689 @@ -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"]} @@ -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