From 58a7177d7f0525e213ab1eebc6c0f6460fe66227 Mon Sep 17 00:00:00 2001 From: Saunak <76943154+Saunakghosh10@users.noreply.github.com> Date: Sat, 15 Jul 2023 01:16:18 +0530 Subject: [PATCH] Add custom_bar_plot() function formatted the setup.py code a bit --- galleries/plot_types/3D/custom_bar_plot.py | 27 +++++++++++++++++++++ setup.py | 28 +++++++++++----------- 2 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 galleries/plot_types/3D/custom_bar_plot.py 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