seaborn | Statistical data visualization in Python | Data Visualization library

 by   mwaskom Python Version: 0.12.2 License: BSD-3-Clause

kandi X-RAY | seaborn Summary

seaborn is a Python library typically used in Analytics, Data Visualization, Pandas applications. seaborn has no bugs, it has no vulnerabilities, it has a Permissive License and it has high support. However seaborn build file is not available. You can install using 'pip install seaborn' or download it from GitHub, PyPI.
Statistical data visualization in Python
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        seaborn has a highly active ecosystem.
                        summary
                        It has 10480 star(s) with 1716 fork(s). There are 254 watchers for this library.
                        summary
                        There were 2 major release(s) in the last 6 months.
                        summary
                        There are 102 open issues and 2169 have been closed. On average issues are closed in 86 days. There are 11 open pull requests and 0 closed requests.
                        summary
                        It has a positive sentiment in the developer community.
                        summary
                        The latest version of seaborn is 0.12.2
                        seaborn Support
                          Best in #Data Visualization
                            Average in #Data Visualization
                            seaborn Support
                              Best in #Data Visualization
                                Average in #Data Visualization

                                  kandi-Quality Quality

                                    summary
                                    seaborn has 0 bugs and 0 code smells.
                                    seaborn Quality
                                      Best in #Data Visualization
                                        Average in #Data Visualization
                                        seaborn Quality
                                          Best in #Data Visualization
                                            Average in #Data Visualization

                                              kandi-Security Security

                                                summary
                                                seaborn has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                seaborn code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 0 security hotspots that need review.
                                                seaborn Security
                                                  Best in #Data Visualization
                                                    Average in #Data Visualization
                                                    seaborn Security
                                                      Best in #Data Visualization
                                                        Average in #Data Visualization

                                                          kandi-License License

                                                            summary
                                                            seaborn is licensed under the BSD-3-Clause License. This license is Permissive.
                                                            summary
                                                            Permissive licenses have the least restrictions, and you can use them in most projects.
                                                            seaborn License
                                                              Best in #Data Visualization
                                                                Average in #Data Visualization
                                                                seaborn License
                                                                  Best in #Data Visualization
                                                                    Average in #Data Visualization

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        seaborn releases are available to install and integrate.
                                                                        summary
                                                                        Deployable package is available in PyPI.
                                                                        summary
                                                                        seaborn has no build file. You will be need to create the build yourself to build the component from source.
                                                                        summary
                                                                        Installation instructions are not available. Examples and code snippets are available.
                                                                        summary
                                                                        seaborn saves you 13118 person hours of effort in developing the same functionality from scratch.
                                                                        summary
                                                                        It has 26955 lines of code, 1355 functions and 102 files.
                                                                        summary
                                                                        It has high code complexity. Code complexity directly impacts maintainability of the code.
                                                                        seaborn Reuse
                                                                          Best in #Data Visualization
                                                                            Average in #Data Visualization
                                                                            seaborn Reuse
                                                                              Best in #Data Visualization
                                                                                Average in #Data Visualization
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi has reviewed seaborn and discovered the below as its top functions. This is intended to give you an instant insight into seaborn implemented functionality, and help decide if they suit your requirements.
                                                                                  • Plot a scatter plot
                                                                                    • The legend
                                                                                    • Draw a matplotlib figure
                                                                                    • Add a legend
                                                                                    • Combine the data into a single plot
                                                                                  • Generate a joint -man plot
                                                                                    • Inject kwargs into kwargs
                                                                                    • Plot marginal properties for a function
                                                                                    • Apply func to func
                                                                                  • Plot a lmplot
                                                                                  • Show a dark palette
                                                                                  • Show a light palette
                                                                                  • Plot the marginal properties of a function
                                                                                  • Determine the colormap parameters
                                                                                  • Generate a swarm plot
                                                                                  • Choose the diverging palette
                                                                                  • Call func on func
                                                                                  • Extract the docstring from the file
                                                                                  • Get the plot data
                                                                                  • Combine the data into a new plot
                                                                                  • Choose a cubehelix palette
                                                                                  • Load an example dataset
                                                                                  • Plot clusters of data
                                                                                  • Move a legend
                                                                                  • Plot the residual data
                                                                                  • Set title and col_titles
                                                                                  • Draw a logo
                                                                                  • Chooses a colorbrewer palette
                                                                                  Get all kandi verified functions for this library.
                                                                                  Get all kandi verified functions for this library.

                                                                                  seaborn Key Features

                                                                                  Statistical data visualization in Python

                                                                                  seaborn Examples and Code Snippets

                                                                                  Load data from seaborn .
                                                                                  pythondot imgLines of Code : 21dot imgLicense : Permissive (MIT License)
                                                                                  copy iconCopy
                                                                                  
                                                                                                                      def load_data(dataset_name: str, cola_name: str, colb_name: str) -> np.mat: """ Function used for loading data from the seaborn splitting into x and y points >>> pass # this function has no doctest """ import seaborn as sns data = sns.load_dataset(dataset_name) col_a = np.array(data[cola_name]) # total_bill col_b = np.array(data[colb_name]) # tip mcol_a = np.mat(col_a) mcol_b = np.mat(col_b) m = np.shape(mcol_b)[1] one = np.ones((1, m), dtype=int) # horizontal stacking training_data_x = np.hstack((one.T, mcol_a.T)) return training_data_x, mcol_b, col_a, col_b
                                                                                  seaborn joint plot, how to remove space between marginal axes
                                                                                  Pythondot imgLines of Code : 4dot imgLicense : Strong Copyleft (CC BY-SA 4.0)
                                                                                  copy iconCopy
                                                                                  sns.jointplot(x='sepal_length', y='sepal_width', data=sns.load_dataset('iris'),
                                                                                                kind='kde', cmap='plasma', space=0)
                                                                                  #                                        -------
                                                                                  
                                                                                  How to make a horizontal stacked histplot based on counts?
                                                                                  Pythondot imgLines of Code : 5dot imgLicense : Strong Copyleft (CC BY-SA 4.0)
                                                                                  copy iconCopy
                                                                                  sns.histplot(
                                                                                      data=melt, y='Time', hue='variable', weights='value',
                                                                                      multiple='stack', shrink=0.8, discrete=True,
                                                                                  )
                                                                                  
                                                                                  How to create a seaborn violinplot of a feature that take more than one value?
                                                                                  Pythondot imgLines of Code : 14dot imgLicense : Strong Copyleft (CC BY-SA 4.0)
                                                                                  copy iconCopy
                                                                                  import pandas as pd
                                                                                  import matplotlib.pyplot as plt
                                                                                  import seaborn as sns
                                                                                  
                                                                                  genres = [['action', 'drama', 'comedy'], ['comedy', 'drama'], ['action', 'sci-fi', 'comedy']]
                                                                                  rating = [6, 8, 3]
                                                                                  
                                                                                  data = {'Rating': rating, 'Genres': genres}
                                                                                  df = pd.DataFrame(data=data)
                                                                                  
                                                                                  df = df.explode("Genres")
                                                                                  sns.violinplot(x='Genres', y='Rating', data=df)
                                                                                  plt.show()
                                                                                  
                                                                                  pandas groupby().size(), to excel line graph
                                                                                  Pythondot imgLines of Code : 7dot imgLicense : Strong Copyleft (CC BY-SA 4.0)
                                                                                  copy iconCopy
                                                                                  import seaborn as sns
                                                                                  df = (hap_groups
                                                                                        .reset_index(name='count')
                                                                                        .assign(generation=lambda d: d['Generation'].str.extract('^(\d+)').astype(int))
                                                                                       )
                                                                                  sns.lineplot(data=df, x='generation', y='count', hue='Line', marker='o')
                                                                                  
                                                                                  Creating a Scatter Plot with different colors for a certain column
                                                                                  Pythondot imgLines of Code : 2dot imgLicense : Strong Copyleft (CC BY-SA 4.0)
                                                                                  copy iconCopy
                                                                                  cityScatter.plot(kind='scatter', x='longitude', y='latitude', c='country')
                                                                                  
                                                                                  ValueError: Found unknown categories [nan] in column 2 during fit
                                                                                  Pythondot imgLines of Code : 6dot imgLicense : Strong Copyleft (CC BY-SA 4.0)
                                                                                  copy iconCopy
                                                                                  ['2' '3' '4' '5more' nan]
                                                                                  
                                                                                  `data.dropna(inplace=True)`
                                                                                  
                                                                                  `data = data.dropna()`
                                                                                  
                                                                                  How to plot multiple time series from a CSV while the data points are in different columns
                                                                                  Pythondot imgLines of Code : 22dot imgLicense : Strong Copyleft (CC BY-SA 4.0)
                                                                                  copy iconCopy
                                                                                  print(df)
                                                                                  
                                                                                  # out:
                                                                                       Data      Mean        sd   time__1   time__2   time__3   time__4  \
                                                                                  0  Data_1  0.947667  0.025263  0.501517  0.874750  0.929426  0.953847   
                                                                                  1  Data_2  0.031960  0.017314  0.377588  0.069185  0.037523  0.024028   
                                                                                  
                                                                                      time__5  
                                                                                  0  0.958375  
                                                                                  1  0.021532  
                                                                                  
                                                                                  df.drop(["Mean", "sd"], axis=1).set_index("Data").T
                                                                                  
                                                                                  Data       Data_1    Data_2
                                                                                  time__1  0.501517  0.377588
                                                                                  time__2  0.874750  0.069185
                                                                                  time__3  0.929426  0.037523
                                                                                  time__4  0.953847  0.024028
                                                                                  time__5  0.958375  0.021532
                                                                                  
                                                                                  df.plot()
                                                                                  
                                                                                  How to make combo charts inside subplots using a For loop in Python
                                                                                  Pythondot imgLines of Code : 10dot imgLicense : Strong Copyleft (CC BY-SA 4.0)
                                                                                  copy iconCopy
                                                                                  filt_a= df_a.loc[df_a['Category'] == cat].reset_index()
                                                                                  
                                                                                  # The x-coordinates are not 2020, 2021, 2022.
                                                                                  # They are 0, 1, 2. The *x-labels* are 2020, 2021, 2022
                                                                                  sns.barplot(data=filt_q, x='Year', y='value', ...)
                                                                                  
                                                                                  # The x-coordinates are the index of the filt_a dataframe
                                                                                  # Calling reset_index resets it to 0, 1, 2, ...
                                                                                  sns.lineplot(data=filt_a['Amount'], ...)
                                                                                  
                                                                                  use different data for legend matplotlib
                                                                                  Pythondot imgLines of Code : 5dot imgLicense : Strong Copyleft (CC BY-SA 4.0)
                                                                                  copy iconCopy
                                                                                  import seaborn as sns
                                                                                  
                                                                                  sns.barplot(data=df, x='player', y='wins', hue='position', dodge=False,
                                                                                              palette=dict(zip(df['position'], df['color'])))
                                                                                  
                                                                                  Community Discussions

                                                                                  Trending Discussions on seaborn

                                                                                  Getting Error 0 when plotting boxplot of a filtered dataset
                                                                                  chevron right
                                                                                  Resize axes of top and right joint marginal plots to match central plot with matplotlib
                                                                                  chevron right
                                                                                  How to paste an Excel chart into PowerPoint placeholder using Python?
                                                                                  chevron right
                                                                                  How to install local package with conda
                                                                                  chevron right
                                                                                  How to add median and IQR to seaborn violinplot
                                                                                  chevron right
                                                                                  Can't deploy streamlit app on share.streamlit.io
                                                                                  chevron right
                                                                                  Pandas agg define metric based on data type
                                                                                  chevron right
                                                                                  Heatmap error :'NoneType' object is not callable when using with dataframe
                                                                                  chevron right
                                                                                  Adding columns & values per group occurrence in pandas after filtering
                                                                                  chevron right
                                                                                  Matplotlib scatter plot marker type from dictionary
                                                                                  chevron right

                                                                                  QUESTION

                                                                                  Getting Error 0 when plotting boxplot of a filtered dataset
                                                                                  Asked 2022-Mar-11 at 15:48

                                                                                  I am working on the Kaggle: Abalone dataset and I am facing a weird problem when plotting a boxplot.

                                                                                  import pandas as pd
                                                                                  import seaborn as sns
                                                                                  
                                                                                  df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/abalone/abalone.data', header=None)
                                                                                  df.columns = ['sex', 'Length', 'Diameter', 'Height', 'Whole weight', 'Shucked weight', 'Viscera weight', 'Shell weight', 'rings']
                                                                                  

                                                                                  If a run:

                                                                                  plt.figure(figsize=(16,6))
                                                                                  plt.subplot(121)
                                                                                  sns.boxplot(data=df['rings'])
                                                                                  

                                                                                  working perfectly!

                                                                                  If I filter the dataset by sex like this:

                                                                                  df_f = df[df['sex']=='F']
                                                                                  df_m = df[df['sex']=='M']
                                                                                  df_i = df[df['sex']=='I']
                                                                                  

                                                                                  df_f = (1307,9), df_m=(1528,9) and df_i=(1342,9)

                                                                                  And I run:

                                                                                  plt.figure(figsize=(16,6))
                                                                                  plt.subplot(121)
                                                                                  sns.boxplot(data=df_m['rings'])
                                                                                  

                                                                                  working perfectly!

                                                                                  But if I run the code above for df_f and df_i datasets I get an error:

                                                                                  ---------------------------------------------------------------------------
                                                                                  KeyError                                  Traceback (most recent call last)
                                                                                  ~/anaconda3/lib/python3.9/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
                                                                                     3360             try:
                                                                                  -> 3361                 return self._engine.get_loc(casted_key)
                                                                                     3362             except KeyError as err:
                                                                                  
                                                                                  ~/anaconda3/lib/python3.9/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
                                                                                  
                                                                                  ~/anaconda3/lib/python3.9/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
                                                                                  
                                                                                  pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
                                                                                  
                                                                                  pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
                                                                                  
                                                                                  KeyError: 0
                                                                                  
                                                                                  The above exception was the direct cause of the following exception:
                                                                                  
                                                                                  KeyError                                  Traceback (most recent call last)
                                                                                  /tmp/ipykernel_434828/3363262611.py in 
                                                                                  ----> 1 sns.boxplot(data=df_f['Rings'])
                                                                                  
                                                                                  ~/anaconda3/lib/python3.9/site-packages/seaborn/_decorators.py in inner_f(*args, **kwargs)
                                                                                       44             )
                                                                                       45         kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
                                                                                  ---> 46         return f(**kwargs)
                                                                                       47     return inner_f
                                                                                       48 
                                                                                  
                                                                                  ~/anaconda3/lib/python3.9/site-packages/seaborn/categorical.py in boxplot(x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth, whis, ax, **kwargs)
                                                                                     2241 ):
                                                                                     2242 
                                                                                  -> 2243     plotter = _BoxPlotter(x, y, hue, data, order, hue_order,
                                                                                     2244                           orient, color, palette, saturation,
                                                                                     2245                           width, dodge, fliersize, linewidth)
                                                                                  
                                                                                  ~/anaconda3/lib/python3.9/site-packages/seaborn/categorical.py in __init__(self, x, y, hue, data, order, hue_order, orient, color, palette, saturation, width, dodge, fliersize, linewidth)
                                                                                      404                  width, dodge, fliersize, linewidth):
                                                                                      405 
                                                                                  --> 406         self.establish_variables(x, y, hue, data, orient, order, hue_order)
                                                                                      407         self.establish_colors(color, palette, saturation)
                                                                                      408 
                                                                                  
                                                                                  ~/anaconda3/lib/python3.9/site-packages/seaborn/categorical.py in establish_variables(self, x, y, hue, data, orient, order, hue_order, units)
                                                                                       96                 if hasattr(data, "shape"):
                                                                                       97                     if len(data.shape) == 1:
                                                                                  ---> 98                         if np.isscalar(data[0]):
                                                                                       99                             plot_data = [data]
                                                                                      100                         else:
                                                                                  
                                                                                  ~/anaconda3/lib/python3.9/site-packages/pandas/core/series.py in __getitem__(self, key)
                                                                                      940 
                                                                                      941         elif key_is_scalar:
                                                                                  --> 942             return self._get_value(key)
                                                                                      943 
                                                                                      944         if is_hashable(key):
                                                                                  
                                                                                  ~/anaconda3/lib/python3.9/site-packages/pandas/core/series.py in _get_value(self, label, takeable)
                                                                                     1049 
                                                                                     1050         # Similar to Index.get_value, but we do not fall back to positional
                                                                                  -> 1051         loc = self.index.get_loc(label)
                                                                                     1052         return self.index._get_values_for_loc(self, loc, label)
                                                                                     1053 
                                                                                  
                                                                                  ~/anaconda3/lib/python3.9/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
                                                                                     3361                 return self._engine.get_loc(casted_key)
                                                                                     3362             except KeyError as err:
                                                                                  -> 3363                 raise KeyError(key) from err
                                                                                     3364 
                                                                                     3365         if is_scalar(key) and isna(key) and not self.hasnans:
                                                                                  
                                                                                  KeyError: 0
                                                                                  

                                                                                  There's no missing values, all values are int.

                                                                                  What am I missing here?

                                                                                  ANSWER

                                                                                  Answered 2022-Mar-10 at 10:38

                                                                                  If you want a box plot per value of a categorical column I suggest:

                                                                                  sns.boxplot(data=df, x='rings', y='sex')
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/71422431

                                                                                  QUESTION

                                                                                  Resize axes of top and right joint marginal plots to match central plot with matplotlib
                                                                                  Asked 2022-Feb-15 at 01:17

                                                                                  How do you size the axes of a marginal plot to match the size of a non-square central plot using matplotlib?

                                                                                  In the image, you'll see that the top marginal plot is too wide, even though it shares the x-axis labels.

                                                                                  Context: I'm trying to create a joint plot like in Seaborn, but with a non-square heatmap at center and bar graphs as the marginal plots. JointGrids isn't designed to work with heatmaps (which is okay, on to matplotlib!). Merging a matplotlib heatmap with subplot barplots gets me close, but I find one bargraph's axis is larger than the central heatmap even when I share axes.

                                                                                  Minimum working example:

                                                                                  import numpy as np
                                                                                  import matplotlib.pyplot as plt
                                                                                  import pandas as pd
                                                                                  
                                                                                  ### Function from matplotlib ################################################
                                                                                  def heatmap(data, row_labels, col_labels, ax=None,
                                                                                              cbar_kw={}, cbarlabel="", **kwargs):
                                                                                      """
                                                                                      Create a heatmap from a numpy array and two lists of labels.
                                                                                  
                                                                                      Parameters
                                                                                      ----------
                                                                                      data
                                                                                          A 2D numpy array of shape (M, N).
                                                                                      row_labels
                                                                                          A list or array of length M with the labels for the rows.
                                                                                      col_labels
                                                                                          A list or array of length N with the labels for the columns.
                                                                                      ax
                                                                                          A `matplotlib.axes.Axes` instance to which the heatmap is plotted.  If
                                                                                          not provided, use current axes or create a new one.  Optional.
                                                                                      cbar_kw
                                                                                          A dictionary with arguments to `matplotlib.Figure.colorbar`.  Optional.
                                                                                      cbarlabel
                                                                                          The label for the colorbar.  Optional.
                                                                                      **kwargs
                                                                                          All other arguments are forwarded to `imshow`.
                                                                                      """
                                                                                  
                                                                                      if not ax:
                                                                                          ax = plt.gca()
                                                                                  
                                                                                      # Plot the heatmap
                                                                                      im = ax.imshow(data, **kwargs)
                                                                                  
                                                                                      # Create colorbar
                                                                                      cbar = ax.figure.colorbar(im, ax=ax, **cbar_kw)
                                                                                      cbar.ax.set_ylabel(cbarlabel, rotation=-90, va="bottom")
                                                                                  
                                                                                      # Show all ticks and label them with the respective list entries.
                                                                                      ax.set_xticks(np.arange(data.shape[1]), labels=col_labels)
                                                                                      ax.set_yticks(np.arange(data.shape[0]), labels=row_labels)
                                                                                  
                                                                                      # Rotate the tick labels and set their alignment.
                                                                                      plt.setp(ax.get_xticklabels(), rotation=-30, ha="right",
                                                                                               rotation_mode="anchor")
                                                                                  
                                                                                      # Turn spines off and create white grid.
                                                                                      ax.spines[:].set_visible(False)
                                                                                  
                                                                                      ax.set_xticks(np.arange(data.shape[1]+1)-.5, minor=True)
                                                                                      ax.set_yticks(np.arange(data.shape[0]+1)-.5, minor=True)
                                                                                      ax.grid(which="minor", color="w", linestyle='-', linewidth=3)
                                                                                      ax.tick_params(which="minor", bottom=False, left=False)
                                                                                  
                                                                                      return im, cbar
                                                                                  
                                                                                  ### Now this specific case ################################################
                                                                                  
                                                                                  # Make dataframe
                                                                                  dd = {f'Col_{col}': [col*x**2 for x in range(25)] for col in range(16)}
                                                                                  index = [f'Row_{x}' for x in range(25)]
                                                                                  df = pd.DataFrame(dd, index=index)
                                                                                  
                                                                                  # Make means by axis
                                                                                  ax0_means = df.mean(axis=0)
                                                                                  ax1_means = df.mean(axis=1)
                                                                                  
                                                                                  # Build figure and axes
                                                                                  fig, axs = plt.subplots(2, 2, sharex="col", sharey="row", figsize=(16,16),
                                                                                      gridspec_kw=dict(height_ratios=[1, 3],width_ratios=[3, 1]))
                                                                                  axs[0, 1].set_visible(False)
                                                                                  axs[0, 0].set_box_aspect(1/3)
                                                                                  axs[1, 1].set_box_aspect(3/1)
                                                                                  
                                                                                  # Plot data
                                                                                  im, cbar = heatmap(df, df.index, df.columns, ax=axs[1,0])
                                                                                  plt.setp(axs[1,0].get_xticklabels(), rotation=45, ha="right",
                                                                                       rotation_mode="anchor")
                                                                                  
                                                                                  # Rotate the tick labels and set their alignment.
                                                                                  axs[1, 1].barh(y=ax1_means.index, width=ax1_means.values)
                                                                                  axs[0, 0].bar(x=ax0_means.index, height=ax0_means.values)
                                                                                  plt.show()
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2022-Feb-15 at 01:17

                                                                                  As the heatmap gets a default "equal" aspect ratio, and gets shrunk due to the colorbar, an idea is to manually resize the histograms once everything is created.

                                                                                  from matplotlib.transforms import Bbox
                                                                                  
                                                                                  # code added at the end, just before plt.show()
                                                                                  (x0m, y0m), (x1m, y1m) = axs[1, 0].get_position().get_points()  # main heatmap
                                                                                  (x0h, y0h), (x1h, y1h) = axs[0, 0].get_position().get_points()  # horizontal histogram
                                                                                  axs[0, 0].set_position(Bbox([[x0m, y0h], [x1m, y1h]]))
                                                                                  (x0v, y0v), (x1v, y1v) = axs[1, 1].get_position().get_points()  # vertical histogram
                                                                                  axs[1, 1].set_position(Bbox([[x0v, y0m], [x1v, y1m]]))
                                                                                  
                                                                                  plt.show()
                                                                                  

                                                                                  (The following example uses hspace=0.01, wspace=0.02 in the gridspec_kw=)

                                                                                  Source https://stackoverflow.com/questions/71119762

                                                                                  QUESTION

                                                                                  How to paste an Excel chart into PowerPoint placeholder using Python?
                                                                                  Asked 2022-Feb-12 at 02:55

                                                                                  I have an excel file with a series of formatted charts on a tab called Charts. I have named the charts, Figure1, Figure2, Figure3, etc.

                                                                                  I have an existing PowerPoint template. The template has 2 placeholders per slide (so that it can accommodate 2 charts per slide).

                                                                                  I would like to paste Figure1 in the left placeholder of slide 3, and Figure2 in the right placeholder of slide 3. I want to do this in python as the data analysis is done in python and excel is used to share stored results with colleagues.

                                                                                  Attempt 1:

                                                                                  Attempt 1 uses win32com.client. I am following this example: How to copy chart from excel and paste it as chart into powerpoint (not image) using python

                                                                                  but I cannot get the syntax right to insert the chart into the placeholder. When I follow the syntax in the solution, nothing happens and I get a message

                                                                                  >

                                                                                  Current code:

                                                                                  xlApp = win32.Dispatch('Excel.Application')
                                                                                  wb = xlApp.Workbooks.Open(outputPath+'Chart Pack.xlsb')
                                                                                          
                                                                                  pptApp = win32.Dispatch('PowerPoint.Application')
                                                                                  ppt = pptApp.Presentations.Open(template)
                                                                                          
                                                                                  # attempt 1
                                                                                  wb.sheets('Charts').ChartObjects('Figure1').Copy
                                                                                  ppt.slides[2].Shapes.Paste
                                                                                      
                                                                                  # attempt 2
                                                                                  wb.sheets('Charts').ChartObjects('Figure1').Copy
                                                                                  ppt.slides[2].placeholders[1].Paste
                                                                                  

                                                                                  Attempt 2:

                                                                                  Attempt 2 uses python-pptx. I looked at the documentation here: https://python-pptx.readthedocs.io/en/latest/user/placeholders-using.html

                                                                                  but the example involves creating an excel chart from scratch in PowerPoint (I am not sure why you would ever do that), and I can't figure out the syntax to insert an existing chart from excel.

                                                                                  Current code:

                                                                                  from pptx import Presentation
                                                                                  
                                                                                  xlApp = win32.Dispatch('Excel.Application')
                                                                                  wb = xlApp.Workbooks.Open(outputPath+'Chart Pack.xlsb')
                                                                                      
                                                                                  prs = Presentation(template)
                                                                                  slide = prs.slides[3]
                                                                                      
                                                                                  for shape in slide.placeholders:
                                                                                      print('%d %s' % (shape.placeholder_format.idx, shape.name))
                                                                                  
                                                                                  placeholder = prs.slides[3].placeholders[1]
                                                                                  placeholder.name
                                                                                  placeholder.placeholder_format.type
                                                                                  placeholder.insert_chart(wb.sheets('Charts').ChartObjects('Figure1').Copy)
                                                                                  

                                                                                  Requirements:

                                                                                  1. I would like to paste the excel chart as an excel object (rather than as a picture) as my colleague likes to be able to click on data series to get the underlying values etc.

                                                                                  2. I would like to paste the chart inside a placeholder (rather than on top of it).

                                                                                  3. I don't want to generate a new chart in PowerPoint as most examples do. A colleague has prepared an excel dashboard and formatted a number of charts as desired, and doing it all from scratch would be laborious.

                                                                                  4. I don't want to do this in VBA. I would like to do it in python as it is part of a broader program.

                                                                                  5. I don't want to use something like plotnine, seaborn, matplotlib etc. As per 1, my colleague likes excel objects that he can click on to show underlying values. This can't be done in these programs.

                                                                                  Python should be able to do this. Any ideas?

                                                                                  ANSWER

                                                                                  Answered 2022-Feb-12 at 02:55

                                                                                  You're very close! Copy and Paste are methods, so to call them you need to add brackets after them, e.g. Copy().

                                                                                  To get slide 2, you need to use the Item method of the Slides class: ppt.Slides.Item(2)

                                                                                  import win32com.client as win32
                                                                                  
                                                                                  xlApp = win32.Dispatch('Excel.Application')
                                                                                  wb = xlApp.Workbooks.Open(outputPath+'Chart Pack.xlsb')
                                                                                  
                                                                                  pptApp = win32.Dispatch('PowerPoint.Application')
                                                                                  ppt = pptApp.Presentations.Open(template)
                                                                                  
                                                                                  slide_num = 3
                                                                                  LEFT_PLACEHOLDER = 3
                                                                                  RIGHT_PLACEHOLDER = 2
                                                                                  
                                                                                  # Figure1
                                                                                  window.View.GotoSlide(slide_num)
                                                                                  wb.sheets('Charts').ChartObjects('Figure1').Copy()
                                                                                  ppt.Slides.Item(slide_num).Shapes.Paste().Select()
                                                                                  window.Selection.Cut()
                                                                                  ppt.Slides.Item(slide_num).Shapes(LEFT_PLACEHOLDER).Select()
                                                                                  window.View.Paste()
                                                                                  
                                                                                  # Figure2
                                                                                  window.View.GotoSlide(slide_num)
                                                                                  wb.sheets('Charts').ChartObjects('Figure2').Copy()
                                                                                  ppt.Slides.Item(slide_num).Shapes.Paste().Select()
                                                                                  window.Selection.Cut()
                                                                                  ppt.Slides.Item(slide_num).Shapes(RIGHT_PLACEHOLDER).Select()
                                                                                  window.View.Paste()
                                                                                  

                                                                                  EDIT: I was able to paste the chart directly into the placeholder after fiddling around a bit trying to implement the solution in this answer. It a bit hacky, but it works.

                                                                                  Source https://stackoverflow.com/questions/71031183

                                                                                  QUESTION

                                                                                  How to install local package with conda
                                                                                  Asked 2022-Feb-05 at 04:16

                                                                                  I have a local python project called jive that I would like to use in an another project. My current method of using jive in other projects is to activate the conda env for the project, then move to my jive directory and use python setup.py install. This works fine, and when I use conda list, I see everything installed in the env including jive, with a note that jive was installed using pip.

                                                                                  But what I really want is to do this with full conda. When I want to use jive in another project, I want to just put jive in that projects environment.yml.

                                                                                  So I did the following:

                                                                                  1. write a simple meta.yaml so I could use conda-build to build jive locally
                                                                                  2. build jive with conda build .
                                                                                  3. I looked at the tarball that was produced and it does indeed contain the jive source as expected
                                                                                  4. In my other project, add jive to the dependencies in environment.yml, and add 'local' to the list of channels.
                                                                                  5. create a conda env using that environment.yml.

                                                                                  When I activate the environment and use conda list, it lists all the dependencies including jive, as desired. But when I open python interpreter, I cannot import jive, it says there is no such package. (If use python setup.py install, I can import it.) How can I fix the build/install so that this works?

                                                                                  Here is the meta.yaml, which lives in the jive project top level directory:

                                                                                  package:
                                                                                    name: jive
                                                                                    version: "0.2.1"
                                                                                  
                                                                                  source:
                                                                                    path: .
                                                                                  
                                                                                  build:
                                                                                    script: python -m pip install --no-deps --ignore-installed .
                                                                                  
                                                                                  requirements:
                                                                                    host:
                                                                                       - python>=3.5
                                                                                       - pip
                                                                                       - setuptools
                                                                                    run:
                                                                                       - python>=3.5
                                                                                       - numpy
                                                                                       - pandas
                                                                                       - scipy
                                                                                       - seaborn
                                                                                       - matplotlib
                                                                                       - scikit-learn
                                                                                       - statsmodels
                                                                                       - joblib
                                                                                       - bokeh
                                                                                  
                                                                                  test:
                                                                                    imports: jive
                                                                                  

                                                                                  And here is the output of conda build .

                                                                                  No numpy version specified in conda_build_config.yaml.  Falling back to default numpy value of 1.16
                                                                                  WARNING:conda_build.metadata:No numpy version specified in conda_build_config.yaml.  Falling back to default numpy value of 1.16
                                                                                  Adding in variants from internal_defaults
                                                                                  INFO:conda_build.variants:Adding in variants from internal_defaults
                                                                                  Adding in variants from /Users/thomaskeefe/.conda/conda_build_config.yaml
                                                                                  INFO:conda_build.variants:Adding in variants from /Users/thomaskeefe/.conda/conda_build_config.yaml
                                                                                  Attempting to finalize metadata for jive
                                                                                  INFO:conda_build.metadata:Attempting to finalize metadata for jive
                                                                                  Collecting package metadata (repodata.json): ...working... done
                                                                                  Solving environment: ...working... done
                                                                                  Collecting package metadata (repodata.json): ...working... done
                                                                                  Solving environment: ...working... done
                                                                                  BUILD START: ['jive-0.2.1-py310_0.tar.bz2']
                                                                                  Collecting package metadata (repodata.json): ...working... done
                                                                                  Solving environment: ...working... done
                                                                                  
                                                                                  ## Package Plan ##
                                                                                  
                                                                                    environment location: /opt/miniconda3/conda-bld/jive_1642185595622/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pla
                                                                                  
                                                                                  
                                                                                  The following NEW packages will be INSTALLED:
                                                                                  
                                                                                      bzip2:           1.0.8-h1de35cc_0
                                                                                      ca-certificates: 2021.10.26-hecd8cb5_2
                                                                                      certifi:         2021.5.30-py310hecd8cb5_0
                                                                                      libcxx:          12.0.0-h2f01273_0
                                                                                      libffi:          3.3-hb1e8313_2
                                                                                      ncurses:         6.3-hca72f7f_2
                                                                                      openssl:         1.1.1m-hca72f7f_0
                                                                                      pip:             21.2.4-py310hecd8cb5_0
                                                                                      python:          3.10.0-hdfd78df_3
                                                                                      readline:        8.1.2-hca72f7f_1
                                                                                      setuptools:      58.0.4-py310hecd8cb5_0
                                                                                      sqlite:          3.37.0-h707629a_0
                                                                                      tk:              8.6.11-h7bc2e8c_0
                                                                                      tzdata:          2021e-hda174b7_0
                                                                                      wheel:           0.37.1-pyhd3eb1b0_0
                                                                                      xz:              5.2.5-h1de35cc_0
                                                                                      zlib:            1.2.11-h4dc903c_4
                                                                                  
                                                                                  Preparing transaction: ...working... done
                                                                                  Verifying transaction: ...working... done
                                                                                  Executing transaction: ...working... done
                                                                                  Collecting package metadata (repodata.json): ...working... done
                                                                                  Solving environment: ...working... done
                                                                                  Copying /Users/thomaskeefe/Documents/py_jive to /opt/miniconda3/conda-bld/jive_1642185595622/work/
                                                                                  source tree in: /opt/miniconda3/conda-bld/jive_1642185595622/work
                                                                                  export PREFIX=/opt/miniconda3/conda-bld/jive_1642185595622/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pla
                                                                                  export BUILD_PREFIX=/opt/miniconda3/conda-bld/jive_1642185595622/_build_env
                                                                                  export SRC_DIR=/opt/miniconda3/conda-bld/jive_1642185595622/work
                                                                                  Processing $SRC_DIR
                                                                                    DEPRECATION: A future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.
                                                                                     pip 21.3 will remove support for this functionality. You can find discussion regarding this at https://github.com/pypa/pip/issues/7555.
                                                                                  Building wheels for collected packages: jive
                                                                                    Building wheel for jive (setup.py): started
                                                                                    Building wheel for jive (setup.py): finished with status 'done'
                                                                                    Created wheel for jive: filename=jive-0.2.1-py3-none-any.whl size=46071 sha256=b312955cb2fd917bc4e684a575407b884190680f2dddad7fcb9ac25e5b290fc9
                                                                                    Stored in directory: /private/tmp/pip-ephem-wheel-cache-rbpkt2an/wheels/15/68/82/4ed7cd246fbc4c72cf764b425a03230247589bd2394a7e457b
                                                                                  Successfully built jive
                                                                                  Installing collected packages: jive
                                                                                  Successfully installed jive-0.2.1
                                                                                  
                                                                                  Resource usage statistics from building jive:
                                                                                     Process count: 3
                                                                                     CPU time: Sys=0:00:00.3, User=0:00:00.5
                                                                                     Memory: 53.7M
                                                                                     Disk usage: 50.4K
                                                                                     Time elapsed: 0:00:06.1
                                                                                  
                                                                                  
                                                                                  Packaging jive
                                                                                  INFO:conda_build.build:Packaging jive
                                                                                  INFO conda_build.build:build(2289): Packaging jive
                                                                                  Packaging jive-0.2.1-py310_0
                                                                                  INFO:conda_build.build:Packaging jive-0.2.1-py310_0
                                                                                  INFO conda_build.build:bundle_conda(1529): Packaging jive-0.2.1-py310_0
                                                                                  compiling .pyc files...
                                                                                  number of files: 70
                                                                                  Fixing permissions
                                                                                  INFO :: Time taken to mark (prefix)
                                                                                          0 replacements in 0 files was 0.06 seconds
                                                                                  TEST START: /opt/miniconda3/conda-bld/osx-64/jive-0.2.1-py310_0.tar.bz2
                                                                                  Adding in variants from /var/folders/dd/t85p2jdn3sd11bsdnl7th6p00000gn/T/tmp4o3im7d1/info/recipe/conda_build_config.yaml
                                                                                  INFO:conda_build.variants:Adding in variants from /var/folders/dd/t85p2jdn3sd11bsdnl7th6p00000gn/T/tmp4o3im7d1/info/recipe/conda_build_config.yaml
                                                                                  INFO conda_build.variants:_combine_spec_dictionaries(234): Adding in variants from /var/folders/dd/t85p2jdn3sd11bsdnl7th6p00000gn/T/tmp4o3im7d1/info/recipe/conda_build_config.yaml
                                                                                  Renaming work directory '/opt/miniconda3/conda-bld/jive_1642185595622/work' to '/opt/miniconda3/conda-bld/jive_1642185595622/work_moved_jive-0.2.1-py310_0_osx-64'
                                                                                  INFO:conda_build.utils:Renaming work directory '/opt/miniconda3/conda-bld/jive_1642185595622/work' to '/opt/miniconda3/conda-bld/jive_1642185595622/work_moved_jive-0.2.1-py310_0_osx-64'
                                                                                  INFO conda_build.utils:shutil_move_more_retrying(2091): Renaming work directory '/opt/miniconda3/conda-bld/jive_1642185595622/work' to '/opt/miniconda3/conda-bld/jive_1642185595622/work_moved_jive-0.2.1-py310_0_osx-64'
                                                                                  shutil.move(work)=/opt/miniconda3/conda-bld/jive_1642185595622/work, dest=/opt/miniconda3/conda-bld/jive_1642185595622/work_moved_jive-0.2.1-py310_0_osx-64)
                                                                                  INFO:conda_build.utils:shutil.move(work)=/opt/miniconda3/conda-bld/jive_1642185595622/work, dest=/opt/miniconda3/conda-bld/jive_1642185595622/work_moved_jive-0.2.1-py310_0_osx-64)
                                                                                  INFO conda_build.utils:shutil_move_more_retrying(2098): shutil.move(work)=/opt/miniconda3/conda-bld/jive_1642185595622/work, dest=/opt/miniconda3/conda-bld/jive_1642185595622/work_moved_jive-0.2.1-py310_0_osx-64)
                                                                                  Collecting package metadata (repodata.json): ...working... done
                                                                                  Solving environment: ...working... done
                                                                                  
                                                                                  ## Package Plan ##
                                                                                  
                                                                                    environment location: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol
                                                                                  
                                                                                  
                                                                                  The following NEW packages will be INSTALLED:
                                                                                  
                                                                                      blas:              1.0-mkl
                                                                                      bokeh:             2.4.2-py39hecd8cb5_0
                                                                                      bottleneck:        1.3.2-py39he3068b8_1
                                                                                      brotli:            1.0.9-hb1e8313_2
                                                                                      ca-certificates:   2021.10.26-hecd8cb5_2
                                                                                      certifi:           2021.10.8-py39hecd8cb5_2
                                                                                      cycler:            0.11.0-pyhd3eb1b0_0
                                                                                      fonttools:         4.25.0-pyhd3eb1b0_0
                                                                                      freetype:          2.11.0-hd8bbffd_0
                                                                                      giflib:            5.2.1-haf1e3a3_0
                                                                                      intel-openmp:      2021.4.0-hecd8cb5_3538
                                                                                      jinja2:            3.0.2-pyhd3eb1b0_0
                                                                                      jive:              0.2.1-py310_0            local
                                                                                      joblib:            1.1.0-pyhd3eb1b0_0
                                                                                      jpeg:              9d-h9ed2024_0
                                                                                      kiwisolver:        1.3.1-py39h23ab428_0
                                                                                      lcms2:             2.12-hf1fd2bf_0
                                                                                      libcxx:            12.0.0-h2f01273_0
                                                                                      libffi:            3.3-hb1e8313_2
                                                                                      libgfortran:       3.0.1-h93005f0_2
                                                                                      libpng:            1.6.37-ha441bb4_0
                                                                                      libtiff:           4.2.0-h87d7836_0
                                                                                      libwebp:           1.2.0-hacca55c_0
                                                                                      libwebp-base:      1.2.0-h9ed2024_0
                                                                                      llvm-openmp:       12.0.0-h0dcd299_1
                                                                                      lz4-c:             1.9.3-h23ab428_1
                                                                                      markupsafe:        2.0.1-py39h9ed2024_0
                                                                                      matplotlib:        3.5.0-py39hecd8cb5_0
                                                                                      matplotlib-base:   3.5.0-py39h4f681db_0
                                                                                      mkl:               2021.4.0-hecd8cb5_637
                                                                                      mkl-service:       2.4.0-py39h9ed2024_0
                                                                                      mkl_fft:           1.3.1-py39h4ab4a9b_0
                                                                                      mkl_random:        1.2.2-py39hb2f4e1b_0
                                                                                      munkres:           1.1.4-py_0
                                                                                      ncurses:           6.3-hca72f7f_2
                                                                                      numexpr:           2.8.1-py39h2e5f0a9_0
                                                                                      numpy:             1.21.2-py39h4b4dc7a_0
                                                                                      numpy-base:        1.21.2-py39he0bd621_0
                                                                                      olefile:           0.46-pyhd3eb1b0_0
                                                                                      openssl:           1.1.1m-hca72f7f_0
                                                                                      packaging:         21.3-pyhd3eb1b0_0
                                                                                      pandas:            1.3.5-py39h743cdd8_0
                                                                                      patsy:             0.5.2-py39hecd8cb5_0
                                                                                      pillow:            8.4.0-py39h98e4679_0
                                                                                      pip:               21.2.4-py39hecd8cb5_0
                                                                                      pyparsing:         3.0.4-pyhd3eb1b0_0
                                                                                      python:            3.9.7-h88f2d9e_1
                                                                                      python-dateutil:   2.8.2-pyhd3eb1b0_0
                                                                                      pytz:              2021.3-pyhd3eb1b0_0
                                                                                      pyyaml:            6.0-py39hca72f7f_1
                                                                                      readline:          8.1.2-hca72f7f_1
                                                                                      scikit-learn:      1.0.2-py39hae1ba45_0
                                                                                      scipy:             1.7.3-py39h8c7af03_0
                                                                                      seaborn:           0.11.2-pyhd3eb1b0_0
                                                                                      setuptools:        58.0.4-py39hecd8cb5_0
                                                                                      six:               1.16.0-pyhd3eb1b0_0
                                                                                      sqlite:            3.37.0-h707629a_0
                                                                                      statsmodels:       0.13.0-py39hca72f7f_0
                                                                                      threadpoolctl:     2.2.0-pyh0d69192_0
                                                                                      tk:                8.6.11-h7bc2e8c_0
                                                                                      tornado:           6.1-py39h9ed2024_0
                                                                                      typing_extensions: 3.10.0.2-pyh06a4308_0
                                                                                      tzdata:            2021e-hda174b7_0
                                                                                      wheel:             0.37.1-pyhd3eb1b0_0
                                                                                      xz:                5.2.5-h1de35cc_0
                                                                                      yaml:              0.2.5-haf1e3a3_0
                                                                                      zlib:              1.2.11-h4dc903c_4
                                                                                      zstd:              1.4.9-h322a384_0
                                                                                  
                                                                                  Preparing transaction: ...working... done
                                                                                  Verifying transaction: ...working...
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::intel-openmp-2021.4.0-hecd8cb5_3538, defaults/osx-64::llvm-openmp-12.0.0-h0dcd299_1
                                                                                    path: 'lib/libiomp5.dylib'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'bin/webpinfo'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'bin/webpmux'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'include/webp/decode.h'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'include/webp/encode.h'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'include/webp/mux.h'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'include/webp/mux_types.h'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'include/webp/types.h'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'lib/libwebp.7.dylib'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'lib/libwebp.a'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'lib/libwebp.dylib'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'lib/libwebpdecoder.3.dylib'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'lib/libwebpdecoder.a'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'lib/libwebpdecoder.dylib'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'lib/libwebpmux.3.dylib'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'lib/libwebpmux.a'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'lib/libwebpmux.dylib'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'lib/pkgconfig/libwebp.pc'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'lib/pkgconfig/libwebpdecoder.pc'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'lib/pkgconfig/libwebpmux.pc'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'share/man/man1/cwebp.1'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'share/man/man1/dwebp.1'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'share/man/man1/webpinfo.1'
                                                                                  
                                                                                  
                                                                                  ClobberWarning: This transaction has incompatible packages due to a shared path.
                                                                                    packages: defaults/osx-64::libwebp-base-1.2.0-h9ed2024_0, defaults/osx-64::libwebp-1.2.0-hacca55c_0
                                                                                    path: 'share/man/man1/webpmux.1'
                                                                                  
                                                                                  
                                                                                  
                                                                                  done
                                                                                  Executing transaction: ...working...
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/llvm-openmp-12.0.0-h0dcd299_1/lib/libiomp5.dylib
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/libiomp5.dylib
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/bin/webpinfo
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/bin/webpinfo
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/bin/webpmux
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/bin/webpmux
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/include/webp/decode.h
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/include/webp/decode.h
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/include/webp/encode.h
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/include/webp/encode.h
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/include/webp/mux.h
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/include/webp/mux.h
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/include/webp/mux_types.h
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/include/webp/mux_types.h
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/include/webp/types.h
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/include/webp/types.h
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/lib/libwebp.7.dylib
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/libwebp.7.dylib
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/lib/libwebp.a
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/libwebp.a
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/lib/libwebp.dylib
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/libwebp.dylib
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/lib/libwebpdecoder.3.dylib
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/libwebpdecoder.3.dylib
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/lib/libwebpdecoder.a
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/libwebpdecoder.a
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/lib/libwebpdecoder.dylib
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/libwebpdecoder.dylib
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/lib/libwebpmux.3.dylib
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/libwebpmux.3.dylib
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/lib/libwebpmux.a
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/libwebpmux.a
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/lib/libwebpmux.dylib
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/libwebpmux.dylib
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/.condatmp/1018f8ab-87a7-4fa8-a41c-4c14cc77cfff
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/pkgconfig/libwebp.pc
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/.condatmp/e3701fae-f2cd-44e9-9dc6-c71f499cd2c2
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/pkgconfig/libwebpdecoder.pc
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/.condatmp/0f4bcf50-01e5-404d-b1a4-8a87d45c22c5
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/pkgconfig/libwebpmux.pc
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/share/man/man1/cwebp.1
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/share/man/man1/cwebp.1
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/share/man/man1/dwebp.1
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/share/man/man1/dwebp.1
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/share/man/man1/webpinfo.1
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/share/man/man1/webpinfo.1
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  ClobberWarning: Conda was asked to clobber an existing path.
                                                                                    source path: /opt/miniconda3/pkgs/libwebp-1.2.0-hacca55c_0/share/man/man1/webpmux.1
                                                                                    target path: /opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/share/man/man1/webpmux.1
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                      Installed package of scikit-learn can be accelerated using scikit-learn-intelex.
                                                                                      More details are available here: https://intel.github.io/scikit-learn-intelex
                                                                                  
                                                                                      For example:
                                                                                  
                                                                                          $ conda install scikit-learn-intelex
                                                                                          $ python -m sklearnex my_application.py
                                                                                  
                                                                                  
                                                                                  
                                                                                  done
                                                                                  export PREFIX=/opt/miniconda3/conda-bld/jive_1642185595622/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol
                                                                                  export SRC_DIR=/opt/miniconda3/conda-bld/jive_1642185595622/test_tmp
                                                                                  Traceback (most recent call last):
                                                                                    File "/opt/miniconda3/conda-bld/jive_1642185595622/test_tmp/run_test.py", line 2, in 
                                                                                      import jive
                                                                                  ModuleNotFoundError: No module named 'jive'
                                                                                  import: 'jive'
                                                                                  Tests failed for jive-0.2.1-py310_0.tar.bz2 - moving package to /opt/miniconda3/conda-bld/broken
                                                                                  WARNING:conda_build.build:Tests failed for jive-0.2.1-py310_0.tar.bz2 - moving package to /opt/miniconda3/conda-bld/broken
                                                                                  WARNING conda_build.build:tests_failed(2970): Tests failed for jive-0.2.1-py310_0.tar.bz2 - moving package to /opt/miniconda3/conda-bld/broken
                                                                                  TESTS FAILED: jive-0.2.1-py310_0.tar.bz2
                                                                                  

                                                                                  EDIT: I added a test: section to the meta.yaml as merv suggested.

                                                                                  ANSWER

                                                                                  Answered 2022-Feb-05 at 04:16

                                                                                  The immediate error is that the build is generating a Python 3.10 version, but when testing Conda doesn't recognize any constraint on the Python version, and creates a Python 3.9 environment.

                                                                                  I think the main issue is that python >=3.5 is only a valid constraint when doing noarch builds, which this is not. That is, once a package builds with a given Python version, the version must be constrained to exactly that version (up through minor). So, in this case, the package is built with Python 3.10, but it reports in its metadata that it is compatible with all versions of Python 3.5+, which simply isn't true because Conda Python packages install the modules into Python-version-specific site-packages (e.g., lib/python-3.10/site-packages/jive).

                                                                                  Typically, Python versions are controlled by either the --python argument given to conda-build or a matrix supplied by the conda_build_config.yaml file (see documentation on "Build variants").

                                                                                  Try adjusting the meta.yaml to something like

                                                                                  package:
                                                                                    name: jive
                                                                                    version: "0.2.1"
                                                                                  
                                                                                  source:
                                                                                    path: .
                                                                                  
                                                                                  build:
                                                                                    script: python -m pip install --no-deps --ignore-installed .
                                                                                  
                                                                                  requirements:
                                                                                    host:
                                                                                       - python
                                                                                       - pip
                                                                                       - setuptools
                                                                                    run:
                                                                                       - python
                                                                                       - numpy
                                                                                       - pandas
                                                                                       - scipy
                                                                                       - seaborn
                                                                                       - matplotlib
                                                                                       - scikit-learn
                                                                                       - statsmodels
                                                                                       - joblib
                                                                                       - bokeh
                                                                                  

                                                                                  If you want to use it in a Python 3.9 environment, then use conda build --python 3.9 ..

                                                                                  Source https://stackoverflow.com/questions/70705250

                                                                                  QUESTION

                                                                                  How to add median and IQR to seaborn violinplot
                                                                                  Asked 2022-Jan-14 at 18:59

                                                                                  I want to add the median and IQ values to the violin plot. However, I didn't find its argument.

                                                                                  import seaborn as sns
                                                                                  sns.set_theme(style="whitegrid")
                                                                                  tips = sns.load_dataset("tips")
                                                                                  ax = sns.violinplot(x=tips["total_bill"])
                                                                                  ax = sns.violinplot(x="day", y="total_bill", hue="sex",
                                                                                                      data=tips, palette="Set2", split=True,
                                                                                                      scale="count", inner="quartile")
                                                                                  plt.show()
                                                                                  

                                                                                  For instance, I want such a notation for all of the graphs per gender:

                                                                                  I am fine to do it with other packages if it is available for them. However, I want to have violin plots rather than boxplots.

                                                                                  ANSWER

                                                                                  Answered 2022-Jan-14 at 18:59

                                                                                  If you look at the lines in ax you can see that they contain the coordinates of the quartile and median lines (see below)

                                                                                  So we could just take the non-zero element from the first array in each line, and the first element of the second array to get the x and y, and use the y as the text value.

                                                                                  import seaborn as sns
                                                                                  import matplotlib.pyplot as plt
                                                                                  sns.set(rc={'figure.figsize':(20,14)})
                                                                                  sns.set_theme(style="whitegrid")
                                                                                  tips = sns.load_dataset("tips")
                                                                                  ax = sns.violinplot(x="day", y="total_bill", hue="sex",
                                                                                                      data=tips, palette="Set2", split=True,
                                                                                                      scale="count", inner="quartile")
                                                                                  
                                                                                  for l in ax.lines:
                                                                                      ax.text(l.get_data()[0][l.get_data()[0].nonzero()][0], l.get_data()[1][0], f'{l.get_data()[1][0]:.0f}',size='large')    
                                                                                  

                                                                                  for l in ax.lines:
                                                                                      print(l.get_data())
                                                                                  

                                                                                  Output

                                                                                  (array([-0.33143126,  0.        ]), array([13.6975, 13.6975]))
                                                                                  (array([-0.37082654,  0.        ]), array([16.975, 16.975]))
                                                                                  (array([-0.25003508,  0.        ]), array([22.36, 22.36]))
                                                                                  (array([0.        , 0.38725949]), array([12.1625, 12.1625]))
                                                                                  (array([0.        , 0.39493527]), array([13.785, 13.785]))
                                                                                  (array([0.        , 0.25722566]), array([18.675, 18.675]))
                                                                                  (array([0.61440819, 1.        ]), array([12.235, 12.235]))
                                                                                  (array([0.62200517, 1.        ]), array([17.215, 17.215]))
                                                                                  (array([0.71996702, 1.        ]), array([26.0825, 26.0825]))
                                                                                  (array([1.        , 1.27676537]), array([11.35, 11.35]))
                                                                                  (array([1.        , 1.35376254]), array([15.38, 15.38]))
                                                                                  (array([1.        , 1.33610081]), array([16.27, 16.27]))
                                                                                  (array([1.63945286, 2.        ]), array([13.905, 13.905]))
                                                                                  (array([1.60991669, 2.        ]), array([18.24, 18.24]))
                                                                                  (array([1.75431475, 2.        ]), array([24.165, 24.165]))
                                                                                  (array([2.        , 2.17418026]), array([14.05, 14.05]))
                                                                                  (array([2.        , 2.18356376]), array([18.36, 18.36]))
                                                                                  (array([2.        , 2.12950778]), array([25.5625, 25.5625]))
                                                                                  (array([2.62638135, 3.        ]), array([15.135, 15.135]))
                                                                                  (array([2.61919886, 3.        ]), array([20.725, 20.725]))
                                                                                  (array([2.73148987, 3.        ]), array([26.55, 26.55]))
                                                                                  (array([3.        , 3.12054879]), array([15.175, 15.175]))
                                                                                  (array([3.        , 3.12176923]), array([17.41, 17.41]))
                                                                                  (array([3.        , 3.07327664]), array([24.8975, 24.8975]))
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/70714905

                                                                                  QUESTION

                                                                                  Can't deploy streamlit app on share.streamlit.io
                                                                                  Asked 2021-Dec-25 at 14:42

                                                                                  I am working with a simple ML model with streamlit. It runs fine on my local machine inside conda environment, but it shows Error installing requirements when I try to deploy it on share.streamlit.io.
                                                                                  The error message is the following:

                                                                                  ERROR: Could not find a version that satisfies the requirement pywin32==303 (from versions: none)
                                                                                  
                                                                                  ERROR: No matching distribution found for pywin32==303
                                                                                  

                                                                                  This is the requirements.txt file for my model:

                                                                                  altair==4.1.0
                                                                                  argon2-cffi==21.3.0
                                                                                  argon2-cffi-bindings==21.2.0
                                                                                  astor==0.8.1
                                                                                  attrs==21.2.0
                                                                                  backcall==0.2.0
                                                                                  base58==2.1.1
                                                                                  bleach==4.1.0
                                                                                  blinker==1.4
                                                                                  cachetools==5.0.0
                                                                                  certifi==2021.10.8
                                                                                  cffi==1.15.0
                                                                                  charset-normalizer==2.0.9
                                                                                  click==7.1.2
                                                                                  colorama==0.4.4
                                                                                  cycler==0.11.0
                                                                                  debugpy==1.5.1
                                                                                  decorator==5.1.0
                                                                                  defusedxml==0.7.1
                                                                                  entrypoints==0.3
                                                                                  fonttools==4.28.5
                                                                                  gitdb==4.0.9
                                                                                  GitPython==3.1.24
                                                                                  idna==3.3
                                                                                  ipykernel==6.6.0
                                                                                  ipython==7.30.1
                                                                                  ipython-genutils==0.2.0
                                                                                  ipywidgets==7.6.5
                                                                                  jedi==0.18.1
                                                                                  Jinja2==3.0.3
                                                                                  joblib==1.1.0
                                                                                  jsonschema==4.3.2
                                                                                  jupyter-client==7.1.0
                                                                                  jupyter-core==4.9.1
                                                                                  jupyterlab-pygments==0.1.2
                                                                                  jupyterlab-widgets==1.0.2
                                                                                  kiwisolver==1.3.2
                                                                                  MarkupSafe==2.0.1
                                                                                  matplotlib==3.5.1
                                                                                  matplotlib-inline==0.1.3
                                                                                  mistune==0.8.4
                                                                                  nbclient==0.5.9
                                                                                  nbconvert==6.3.0
                                                                                  nbformat==5.1.3
                                                                                  nest-asyncio==1.5.4
                                                                                  notebook==6.4.6
                                                                                  numpy==1.21.5
                                                                                  packaging==21.3
                                                                                  pandas==1.3.5
                                                                                  pandocfilters==1.5.0
                                                                                  parso==0.8.3
                                                                                  pickleshare==0.7.5
                                                                                  Pillow==8.4.0
                                                                                  prometheus-client==0.12.0
                                                                                  prompt-toolkit==3.0.24
                                                                                  protobuf==3.19.1
                                                                                  pyarrow==6.0.1
                                                                                  pycparser==2.21
                                                                                  pydeck==0.7.1
                                                                                  Pygments==2.10.0
                                                                                  Pympler==1.0.1
                                                                                  pyparsing==3.0.6
                                                                                  pyrsistent==0.18.0
                                                                                  python-dateutil==2.8.2
                                                                                  pytz==2021.3
                                                                                  pytz-deprecation-shim==0.1.0.post0
                                                                                  pywin32==303
                                                                                  pywinpty==1.1.6
                                                                                  pyzmq==22.3.0
                                                                                  requests==2.26.0
                                                                                  scikit-learn==1.0.1
                                                                                  scipy==1.7.3
                                                                                  seaborn==0.11.2
                                                                                  Send2Trash==1.8.0
                                                                                  six==1.16.0
                                                                                  smmap==5.0.0
                                                                                  streamlit==1.3.0
                                                                                  terminado==0.12.1
                                                                                  testpath==0.5.0
                                                                                  threadpoolctl==3.0.0
                                                                                  toml==0.10.2
                                                                                  toolz==0.11.2
                                                                                  tornado==6.1
                                                                                  traitlets==5.1.1
                                                                                  typing_extensions==4.0.1
                                                                                  tzdata==2021.5
                                                                                  tzlocal==4.1
                                                                                  urllib3==1.26.7
                                                                                  validators==0.18.2
                                                                                  watchdog==2.1.6
                                                                                  wcwidth==0.2.5
                                                                                  webencodings==0.5.1
                                                                                  widgetsnbextension==3.5.2
                                                                                  wincertstore==0.2
                                                                                  

                                                                                  What should I do to resolve this error?

                                                                                  ANSWER

                                                                                  Answered 2021-Dec-25 at 14:42

                                                                                  Streamlit share runs the app in a linux environment meaning there is no pywin32 because this is for windows.

                                                                                  Delete the pywin32 from the requirements file and also the pywinpty==1.1.6 for the same reason.

                                                                                  After deleting these requirements re-deploy your app and it will work.

                                                                                  Source https://stackoverflow.com/questions/70480314

                                                                                  QUESTION

                                                                                  Pandas agg define metric based on data type
                                                                                  Asked 2021-Dec-16 at 12:34

                                                                                  For pandas agg, is there a way to specify the aggregation function based on the data type? For example, all columns of type object get "first", all floats get "mean", and so on? So as to avoid having to type out all the columns with their respective aggregating functions.

                                                                                  Sample data:

                                                                                  import seaborn as sns
                                                                                  iris = sns.load_dataset('iris')
                                                                                  

                                                                                  Desired code:

                                                                                  iris.agg({"object":"first", "float":"mean"})
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2021-Dec-16 at 12:25
                                                                                  def a(x):
                                                                                      if x.dtype == np.dtype('float64'):
                                                                                          dict[x.name] = "mean"
                                                                                      elif x.dtype == np.dtype('object'):
                                                                                          dict[x.name] = "first"
                                                                                  
                                                                                  
                                                                                  dict = {}
                                                                                  
                                                                                  df = df.apply(a)
                                                                                  
                                                                                  iris.agg(dict)
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/70364384

                                                                                  QUESTION

                                                                                  Heatmap error :'NoneType' object is not callable when using with dataframe
                                                                                  Asked 2021-Dec-05 at 09:37

                                                                                  I have this issue with heatmap from seaborn. I don't know how, but seaborn.heatmap() refuses to take in dataframe, it instead show the mentioned error. Seaborn, matplotlib and pandas is up-to-date and I'm using python 3.10 on Visual Studio. The code is just a sample code from seaborn.heatmap itself:

                                                                                  import pandas as pd
                                                                                  import seaborn as sns
                                                                                  import matplotlib.pyplot as plt
                                                                                  flights = sns.load_dataset("flights")
                                                                                  flights = flights.pivot("month", "year", "passengers")
                                                                                  ax=sns.heatmap(flights)
                                                                                  plt.show()
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2021-Dec-05 at 09:37

                                                                                  Use Python 3.9 (or 3.8, 3.7, 3.6) as it seems like both pandas and plt are not quite ready to be used with Python 3.10:

                                                                                  Source https://stackoverflow.com/questions/70232617

                                                                                  QUESTION

                                                                                  Adding columns & values per group occurrence in pandas after filtering
                                                                                  Asked 2021-Dec-03 at 09:52

                                                                                  I have a df

                                                                                  import seaborn as sns
                                                                                  import numpy as np
                                                                                  import pandas as pd
                                                                                  
                                                                                  df = sns.load_dataset('titanic')
                                                                                  

                                                                                  I am trying to add 8 columns from 1-8 which is the age of the passenger and to count how many passengers fit in to each of those categories 1-8

                                                                                  I tried:

                                                                                  df_temp = df.groupby('sex').agg({'fare':np.mean})
                                                                                  

                                                                                  Which returns:

                                                                                          fare
                                                                                  sex 
                                                                                  female  44.48
                                                                                  male    25.52
                                                                                  

                                                                                  Then I have age_buckets = range(1,9) which are the age categories I am interested in.

                                                                                  The goal is to have this kind of structure:

                                                                                  sex            fare                 age_1       age_2       age_3         ...     age_8
                                                                                  male           25                   0           10          3                     x  
                                                                                  female         44                   1           2           2                     y  
                                                                                  

                                                                                  Which would mean that there were 0 age_1 males and 1 girl that was 1 year old and so on.

                                                                                  So I tried the following:

                                                                                  df_age = df[df.age.isin(age_buckets)].groupby(['sex','age']) \
                                                                                                                    .count() \
                                                                                                                    .survived \
                                                                                                                    .reset_index()
                                                                                  

                                                                                  Which returns the data I want but not in the format I can add to my primary df_temp as a column per age.

                                                                                  So at this point I am not sure if this is the right way to achieve the desired result I am trying to create and don't know how to work forward.

                                                                                  ANSWER

                                                                                  Answered 2021-Dec-03 at 09:52

                                                                                  Use cut with crosstab and add DataFrame.add_prefix:

                                                                                  df = (df_temp.join(pd.crosstab(df['sex'],pd.cut(df['age'], 
                                                                                                                                  bins=range(0,9),
                                                                                                                                  labels=range(1,9)))
                                                                                                       .add_prefix('age_')))
                                                                                  print (df)
                                                                                               fare  age_1  age_2  age_3  age_4  age_5  age_6  age_7  age_8
                                                                                  sex                                                                      
                                                                                  female  44.479818      4      6      2      5      4      2      1      2
                                                                                  male    25.523893     10      4      4      5      0      1      2      2
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/70212172

                                                                                  QUESTION

                                                                                  Matplotlib scatter plot marker type from dictionary
                                                                                  Asked 2021-Dec-02 at 18:42

                                                                                  Using Matplotlib to make a scatter plot (not Seaborn, Pandas, or other high-level interface), how can I use a dictionary to specify marker types?

                                                                                  This example works with a color dictionary:

                                                                                  x = [4, 8, 1, 0, 2]
                                                                                  y = [0.1, 1, 0.4, 0.8, 0.9]
                                                                                  name = ["A", "A", "B", "A", "B"]
                                                                                  df = pd.DataFrame(data=zip(x, y, name), columns=["x", "y", "name"])
                                                                                  
                                                                                  colors = {"A": "red", "B": "blue"}
                                                                                  
                                                                                  fig, ax = plt.subplots(1, 1)
                                                                                  ax.scatter(
                                                                                      x=df["x"],
                                                                                      y=df["y"],
                                                                                      facecolors="none",
                                                                                      edgecolors=df["name"].map(colors),
                                                                                  )
                                                                                  

                                                                                  But the following throws an error TypeError: 'Series' objects are mutable, thus they cannot be hashed:

                                                                                  markers = {"A": "v", "B": "D"}
                                                                                  
                                                                                  fig, ax = plt.subplots(1, 1)
                                                                                  ax.scatter(
                                                                                      x=df["x"],
                                                                                      y=df["y"],
                                                                                      facecolors="none",
                                                                                      edgecolors=df["name"].map(colors),
                                                                                      marker=df['name'].map(markers),
                                                                                  )
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2021-Dec-02 at 18:42

                                                                                  Based on the comments by @BigBen, it looks like Matplotlib doesn't support multiple markers. @BigBen linked to a couple of example work-arounds, but I found the following works best for me because it allows me to explicitly relate a keyword to a marker style at the beginning of my code, regardless of what subset of df I am working with. (Real-life data has a dozen "name" values, and I am working with various and mixed subsets based on attributes in other columns.)

                                                                                  x = [4, 8, 1, 0, 2]
                                                                                  y = [0.1, 1, 0.4, 0.8, 0.9]
                                                                                  name = ["A", "A", "B", "A", "B"]
                                                                                  df = pd.DataFrame(data=zip(x, y, name), columns=["x", "y", "name"])
                                                                                  
                                                                                  colors = {"A": "red", "B": "blue"}
                                                                                  markers = {"A": "v", "B": "D"}
                                                                                  
                                                                                  fig, ax = plt.subplots(1, 1)
                                                                                  
                                                                                  for name, group in df.groupby("name"):
                                                                                      group = group.copy()
                                                                                      m = markers.get(name)
                                                                                  
                                                                                      ax.scatter(
                                                                                          x=group["x"],
                                                                                          y=group["y"],
                                                                                          facecolors="none",
                                                                                          edgecolors=group["name"].map(colors),
                                                                                          marker=m,
                                                                                          label=name,
                                                                                      )
                                                                                      ax.legend(loc="lower right")
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/70191327

                                                                                  Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                  Vulnerabilities

                                                                                  No vulnerabilities reported

                                                                                  Install seaborn

                                                                                  You can install using 'pip install seaborn' or download it from GitHub, PyPI.
                                                                                  You can use seaborn like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

                                                                                  Support

                                                                                  For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
                                                                                  Find more information at:
                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit
                                                                                  Install
                                                                                • PyPI

                                                                                  pip install seaborn

                                                                                • CLONE
                                                                                • HTTPS

                                                                                  https://github.com/mwaskom/seaborn.git

                                                                                • CLI

                                                                                  gh repo clone mwaskom/seaborn

                                                                                • sshUrl

                                                                                  git@github.com:mwaskom/seaborn.git

                                                                                • Share this Page

                                                                                  share link

                                                                                  Explore Related Topics

                                                                                  Consider Popular Data Visualization Libraries

                                                                                  Try Top Libraries by mwaskom

                                                                                  seaborn-data

                                                                                  by mwaskomPython

                                                                                  StatApps

                                                                                  by mwaskomR

                                                                                  Psych216

                                                                                  by mwaskomPython

                                                                                  lyman

                                                                                  by mwaskomPython

                                                                                  moss

                                                                                  by mwaskomPython

                                                                                  Compare Data Visualization Libraries with Highest Support

                                                                                  matplotlib

                                                                                  by matplotlib

                                                                                  ipython

                                                                                  by ipython

                                                                                  redash

                                                                                  by getredash

                                                                                  d3

                                                                                  by d3

                                                                                  seaborn

                                                                                  by mwaskom

                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit