0

I grouped the data and tried for a stacked bar chart and it worked fine the figure is also plotted in the interpreter with an ipynb jupyter notebook file as show in the picture attached, but when I want to use that figure in the canvas of matplotlib.backends canvas for displaying plots figure was not plotted just empty axes,

need some solution to save the subplot and utilize it for displaying in canvas

can any share their knowledge with me to solve my problem

    dfd = df.groupby(['Region','Sub-Category']).aggregate({'Sales':sum}).unstack(-2)
    fig, ax = plt.subplots(figsize =(7, 5))

1

below is the core detailed code

  import pandas as pd
  import matplotlib.pyplot as plt
  df = pd.read_excel("C:/Users/OneDrive/Desktop/Excel_files/Sample - Superstore2.xlsx")
  df.groupby(['Category','Sub-Category']).aggregate({'Sales':sum}).unstack(-2).plot(kind = 'bar',stacked= True,figsize = (15,7) )
  plt.show()

this is my full code what I want is like I to want use its figure to display in the Tkinter canvas widget, as like we have option in below possible way as far as my knowledge

      fig, ax = plt.subplots(1, figsize=(7, 5))

by using ax we will plot graphs and those graphs will be stored in fig variable as subplots and this fig variable can be used to display the figure in canvas.

type of fig varibale is -> <class 'matplotlib.figure.Figure'>

but when i use ax for plotting the stacked bar plot its not been plotted properly

  • Can you provide more of your code so that others can test it? [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Michael S. Aug 29 '22 at 11:58
  • Please provide enough code so others can better understand or reproduce the problem. – Community Aug 29 '22 at 11:59

0 Answers0