1

I have a dictionary that looks like this:

habitat_dictionary={'trees':6,
                    'ponds':10,
                    'scrub':23}

I also have a dataframe with many columns, among which are no._trees, no._ponds, no._scrub -for example:

d = {'no._trees': [1, 2], 'no._rabbit_holes':[7,8],'no._ponds':[3,5], 'no._scrub':[3,2],'robin': [0.5, 0.6], 'dove':[0.6,0.2]}
df = pd.DataFrame(data=d)

For each key in the habitat dictionary, I want to create a graph with the key as the x-axis variable, a y-axis variable between 0 and 1, and there would be two lines: one for 'robin' and one for 'dove'.

I have been trying this:

for habitat  in habitat_dictionary.keys():
    out=df.set_index('no._'+str(habitat))[['robin', 'dove']

    out.plot(ylim=(0, 1), xticks=out.index, legend=True)

but I am getting the error: 'TypeError: loop of ufunc does not support argument 0 of type float which has no callable rint method'

I would like to have all the graphs as subplots with a shared title

Niam45
  • 552
  • 2
  • 16
  • 2
    I've voting to close this because the reported error is not reproducible. The code creates 3 plots without issue. [code and plot](https://i.stack.imgur.com/LkW3u.png). Otherwise review this [answer](https://stackoverflow.com/a/68793513/7758804) in [How to plot in multiple subplots](https://stackoverflow.com/q/31726643/7758804) – Trenton McKinney Jun 18 '23 at 19:16
  • Oh, I'll will investigate more my error then....how would I get them as subplots with a shared title? – Niam45 Jun 18 '23 at 19:18
  • 2
    I updated my previous comment. – Trenton McKinney Jun 18 '23 at 19:18
  • You may want to look into using [`seaborn.FacetGrid`](https://seaborn.pydata.org/generated/seaborn.FacetGrid.html). That link includes many examples. – jared Jun 18 '23 at 20:04

0 Answers0