kivy-garden / garden.matplotlib

Matplotlib backends using kivy
MIT License
104 stars 50 forks source link

Multiple subplots not being drawn in FigureCanvasKivy #50

Open janssen opened 7 years ago

janssen commented 7 years ago

I'm using seaborn.jointplot to plot several columns in a pandas DataFrame against each other. Using FigureCanvasKivyAgg, it looks like this:

jointplot-iris-figure-canvas-kivyagg

(This is one of the standard pandas test datasets, the measured lengths and widths of the petals and sepals from three varieties of iris.)

However, when I plot it with FigureCanvasKivy, I get this:

jointplot-iris-figure-canvas-kivy

Looks like something in FigureCanvasKivy is not enumerating all the subplots.

janssen commented 7 years ago

Here's a simple program to illustrate the problem. You need to have matplotlib, pandas, and seaborn installed to run this:

import sys, os

import matplotlib
matplotlib.use("module://kivy.garden.matplotlib.backend_kivyagg")
from kivy.garden.matplotlib import FigureCanvasKivy, FigureCanvasKivyAgg

from matplotlib import pyplot as plt

import pandas
import pandas.io.tests
import seaborn

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

class TestApp(App):

    def build(self):

        box = BoxLayout(orientation="horizontal")

        df = pandas.read_csv(os.path.join(pandas.io.tests.__path__[0], "data", "iris.csv"))
        print df

        seaborn.set_palette('bright')
        seaborn.set_style('whitegrid')
        seaborn.pairplot(data=df,
                         hue="Name",
                         kind="scatter",
                         diag_kind="hist",
                         x_vars=("SepalLength", "SepalWidth"),
                         y_vars=("PetalLength", "PetalWidth"))

        box.add_widget(FigureCanvasKivyAgg(plt.gcf()))
        box.add_widget(FigureCanvasKivy(plt.gcf()))
        return box

if __name__ == "__main__":
    TestApp().run()