Re: get_axes not present?

2021-11-21 Thread Mahmood Naderan via Python-list

>Your example isn't minimal enough for me to be able to pin it down any
>better than that, though.

Chris,
I was able to simply it even further. Please look at this:


$ cat test.batch.csv
Value,Value
10,2
5,2
10,2


$ cat test.py
import pandas as pd
import csv,sys
import matplotlib
import matplotlib.pyplot as plt

df = pd.read_csv('test.batch.csv')
print(df)

def plot_dataframe(df, cnt, axes):
    df.columns = range(1, len(df.columns)+1)   # Ignore the column header
    row = df.iloc[0].astype(int)  # First row in the dataframe
    plt.subplot(2, 1, 1)
    print("axes=", axes)
    print("axes[0]=", axes[0])
    print("cnt=", cnt)
    print("row=", row)
    ax1 = row.plot(label=cnt, ax=axes[0], marker='o')   # Line chart
    ax1.set_ylabel( 'test', fontsize=15 )
    plt.subplot(2, 1, 2)
    df2 = row.value_counts()
    df2.reindex().plot(kind='bar', label=cnt, ax=axes[1])   # Histogram

def plot_kernels(df):
    fig,axes = plt.subplots(2,1, figsize=(20, 15))
    cnt=1
    plot_dataframe(df, cnt, axes)
    cnt = cnt + 1
    for ax in axes:
    ax.legend()
    plt.show()

print("matplotlib version = ",  matplotlib.__version__)
print("pandas version = ", pd.__version__)
print("sys version", sys.version_info)

plot_kernels(df)




And the output is


$ python3 test.py
   Value  Value.1
0 10    2
1  5    2
2 10    2
matplotlib version =  3.3.4
pandas version =  1.2.3
sys version sys.version_info(major=3, minor=8, micro=10, releaselevel='final', 
serial=0)
axes= [ ]
axes[0]= AxesSubplot(0.125,0.53;0.775x0.35)
cnt= 1
row= 1    10
2 2
Name: 0, dtype: int64
Traceback (most recent call last):
  File "test.py", line 41, in 
    plot_kernels(df)
  File "test.py", line 29, in plot_kernels
    plot_dataframe(df, cnt, axes)
  File "test.py", line 19, in plot_dataframe
    ax1 = row.plot(label=cnt, ax=axes[0], marker='o')   # Line chart
  File 
"/home/mnaderan/.local/lib/python3.8/site-packages/pandas/plotting/_core.py", 
line 955, in __call__
    return plot_backend.plot(data, kind=kind, **kwargs)
  File 
"/home/mnaderan/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/__init__.py",
 line 61, in plot
    plot_obj.generate()
  File 
"/home/mnaderan/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 283, in generate
    self._adorn_subplots()
  File 
"/home/mnaderan/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 483, in _adorn_subplots
    all_axes = self._get_subplots()
  File 
"/home/mnaderan/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 903, in _get_subplots
    ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)
AttributeError: 'NoneType' object has no attribute 'get_axes'



Any idea about that?



Regards,
Mahmood

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: get_axes not present?

2021-11-21 Thread Mahmood Naderan via Python-list
>I installed the latest pandas, although on Python 3.10, and the script
>worked without a problem.


Yes as I wrote it works with 1.3.3 but mine is 1.2.3.
I am trying to keep the current version because of the possible future 
consequences. In the end maybe I have to upgrade the pandas.


Regards,
Mahmood



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: get_axes not present?

2021-11-21 Thread MRAB

On 2021-11-21 16:39, Mahmood Naderan via Python-list wrote:

The best way to get
assistance here on the list is to create a minimal, self-contained,
run-able, example program that you can post in its entirety here that
demonstrates the issue.



I created a sample code with input. Since the code processes a csv file to 
group input rows, I also included those in this minimal code but those 
preprocesses are not buggy. In this sample code, I used print() to print 
necessary information. The error exists in the plot function. I tested the 
dictionary build before that and it is fine.


Code is available at https://pastebin.com/giAnjJDV  and the input file 
(test.batch.csv) is available https://pastebin.com/Hdp4Wt9B

The run command is "python3 test.py". With the versions specified in my system, 
here is the full output:





$ python3 test.py
Reading file...
matplotlib version =  3.3.4
pandas version =  1.2.3
sys version sys.version_info(major=3, minor=8, micro=10, releaselevel='final', 
serial=0)
Original dictionary =  {'dummy': Value
M1  0
M2  0
M3  0, 'K1::foo(bar::z(x,u))':    Value  Value
0 10  2
1  5  2
2 10  2, 'K2::foo()':    Value
0 20
1 10
2 15, 'K3::foo(baar::y(z,u))':    Value
0 12
1 13
2 14, 'K3::foo(bar::y(z,u))':    Value
0  6
1  7
2  8}
New dictionary for plot =  {'dummy': Value
M1  0
M2  0
M3  0, 'K1::foo(bar::z(x,u))':    Value  Value
0 10  2
1  5  2
2 10  2, 'K3::foo(bar::y(z,u))':    Value
0  6
1  7
2  8}
Key is  K1::foo(bar::z(x,u))  -> df is Value  Value
0 10  2
1  5  2
2 10  2
axes= [ ]
axes[0]= AxesSubplot(0.125,0.53;0.775x0.35)
cnt= 1
row= 1    10
2 2
Name: 0, dtype: int64
Traceback (most recent call last):
   File "test.py", line 74, in 
     plot_kernels(my_dict2)
   File "test.py", line 52, in plot_kernels
     plot_dataframe(df, cnt, axes)
   File "test.py", line 36, in plot_dataframe
     ax1 = row.plot(label=cnt, ax=axes[0], marker='o')   # Line chart
   File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_core.py", 
line 955, in __call__
     return plot_backend.plot(data, kind=kind, **kwargs)
   File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/__init__.py",
 line 61, in plot
     plot_obj.generate()
   File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 283, in generate
     self._adorn_subplots()
   File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 483, in _adorn_subplots
     all_axes = self._get_subplots()
   File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 903, in _get_subplots
     ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, 
Subplot)
AttributeError: 'NoneType' object has no attribute 'get_axes'



I am pretty sure that there is a version mismatch because on a system with 
Pandas 1.3.3 the output should be like https://imgur.com/a/LZ9eAzl

Any feedback is appreciated.

I installed the latest pandas, although on Python 3.10, and the script 
worked without a problem.

--
https://mail.python.org/mailman/listinfo/python-list


Re: get_axes not present?

2021-11-21 Thread Chris Angelico
On Mon, Nov 22, 2021 at 3:40 AM Mahmood Naderan via Python-list
 wrote:
>   File 
> "/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
>  line 903, in _get_subplots
> ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, 
> Subplot)
> AttributeError: 'NoneType' object has no attribute 'get_axes'
>

My reading of this is that you're trying to do something that depends
on having an associated figure, but you haven't specified the figure.
Look at documentation and examples for the functions you're calling
and see if one of them depends on a figure.

Your example isn't minimal enough for me to be able to pin it down any
better than that, though.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: get_axes not present?

2021-11-21 Thread Mahmood Naderan via Python-list
>The best way to get
>assistance here on the list is to create a minimal, self-contained,
>run-able, example program that you can post in its entirety here that
>demonstrates the issue.


I created a sample code with input. Since the code processes a csv file to 
group input rows, I also included those in this minimal code but those 
preprocesses are not buggy. In this sample code, I used print() to print 
necessary information. The error exists in the plot function. I tested the 
dictionary build before that and it is fine.


Code is available at https://pastebin.com/giAnjJDV  and the input file 
(test.batch.csv) is available https://pastebin.com/Hdp4Wt9B 

The run command is "python3 test.py". With the versions specified in my system, 
here is the full output:





$ python3 test.py
Reading file...
matplotlib version =  3.3.4
pandas version =  1.2.3
sys version sys.version_info(major=3, minor=8, micro=10, releaselevel='final', 
serial=0)
Original dictionary =  {'dummy': Value
M1  0
M2  0
M3  0, 'K1::foo(bar::z(x,u))':    Value  Value
0 10  2
1  5  2
2 10  2, 'K2::foo()':    Value
0 20
1 10
2 15, 'K3::foo(baar::y(z,u))':    Value
0 12
1 13
2 14, 'K3::foo(bar::y(z,u))':    Value
0  6
1  7
2  8}
New dictionary for plot =  {'dummy': Value
M1  0
M2  0
M3  0, 'K1::foo(bar::z(x,u))':    Value  Value
0 10  2
1  5  2
2 10  2, 'K3::foo(bar::y(z,u))':    Value
0  6
1  7
2  8}
Key is  K1::foo(bar::z(x,u))  -> df is Value  Value
0 10  2
1  5  2
2 10  2
axes= [ ]
axes[0]= AxesSubplot(0.125,0.53;0.775x0.35)
cnt= 1
row= 1    10
2 2
Name: 0, dtype: int64
Traceback (most recent call last):
  File "test.py", line 74, in 
    plot_kernels(my_dict2)
  File "test.py", line 52, in plot_kernels
    plot_dataframe(df, cnt, axes)
  File "test.py", line 36, in plot_dataframe
    ax1 = row.plot(label=cnt, ax=axes[0], marker='o')   # Line chart
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_core.py", 
line 955, in __call__
    return plot_backend.plot(data, kind=kind, **kwargs)
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/__init__.py",
 line 61, in plot
    plot_obj.generate()
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 283, in generate
    self._adorn_subplots()
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 483, in _adorn_subplots
    all_axes = self._get_subplots()
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 903, in _get_subplots
    ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)
AttributeError: 'NoneType' object has no attribute 'get_axes'



I am pretty sure that there is a version mismatch because on a system with 
Pandas 1.3.3 the output should be like https://imgur.com/a/LZ9eAzl

Any feedback is appreciated.


Regards,
Mahmood

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: get_axes not present?

2021-11-21 Thread Michael Torrie
On 11/19/21 10:38 AM, Mahmood Naderan wrote:
>> And what is the result of plot()?  Is it a valid object, or is it None?
> 
> Well the error happens on the plot() line. I tried to print some information 
> like this:
> 
> Any thoughts on that?

It's not really possible for us to know what is happening since none of
us are in front of your computer with your code in front of us.  I
cannot run any of your posted code excerpts.  The best way to get
assistance here on the list is to create a minimal, self-contained,
run-able, example program that you can post in its entirety here that
demonstrates the issue. Otherwise all anyone can do is make guesses.

Did you read through the exception message?  It is providing a lot of
information. The message is saying that matplotlib is trying to call
.get_figure() on a self.axes list item, but that is not a valid object,
but is None. The question is, why is that list full of Nones?  Farther
up the traceback it notes that on line 66 of process_csv.py, you make a
call to plot_data() passing it the axes. Perhaps there's something wrong
with the axes object or list you are passing in there.  Did you print
that out to make sure that df, cnt, and axes all contain valid things?

All I can tell you is to use the standard debugging techniques you would
use for any problem.  Use either a debugger or print()'s to print out
the contents and types of each variable to verify they contain the data
you think they do.  If you have nested function calls, break them out
separately so you can examine the inputs and outputs of each of them.
If necessary, trace your way through the matplotlib code, but almost
certainly you'll find the problem is in bad data you are passing to
matplotlib.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: get_axes not present?

2021-11-19 Thread Mahmood Naderan via Python-list
>And what is the result of plot()?  Is it a valid object, or is it None?

Well the error happens on the plot() line. I tried to print some information 
like this:


    print("axes=", axes)
    print("axes[0]=", axes[0])
    print("cnt=", cnt)
    print("row=", row)
    ax1 = row.plot( fontsize=font_size, linewidth=line_width, 
markersize=marker_size, marker='o', title='Raw values', label=cnt, ax=axes[0] )



The output looks like


axes= [ ]
axes[0]= AxesSubplot(0.125,0.53;0.775x0.35)
cnt= 1
row= 1   278528
2   278528
3   278528
4   278528
5   278528
 ...
5604    278528
5605    278528
5606    278528
5607    278528
5608    278528
Name: 4, Length: 5608, dtype: int64
Traceback (most recent call last):
  File "process_csv.py", line 178, in 
    plot_kernels( my_dict2 )
  File "process_csv.py", line 66, in plot_kernels
    should_plot = plot_dataframe(df, cnt, axes)
  File "process_csv.py", line 38, in plot_dataframe
    ax1 = row.plot( fontsize=font_size, linewidth=line_width, 
markersize=marker_size, marker='o', title='Raw values', label=cnt, ax=axes[0] )
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_core.py", 
line 955, in __call__
    return plot_backend.plot(data, kind=kind, **kwargs)
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/__init__.py",
 line 61, in plot
    plot_obj.generate()
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 283, in generate
    self._adorn_subplots()
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 483, in _adorn_subplots
    all_axes = self._get_subplots()
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 903, in _get_subplots
    ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)
AttributeError: 'NoneType' object has no attribute 'get_axes'



The error is weird. I have stick at this error...
Any thoughts on that?


Regards,
Mahmood



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: get_axes not present?

2021-11-18 Thread Michael Torrie
On 11/18/21 10:54 AM, Mahmood Naderan via Python-list wrote:
> As you can see I put the result of plot() to ax1 and then use some functions, 
> e.g. set_ylabel().

And what is the result of plot()?  Is it a valid object, or is it None?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: get_axes not present?

2021-11-18 Thread Mahmood Naderan via Python-list
>It's not saying get_axes doesn't exist because of version skew, it's
>saying that the object returned by the call to the left of it
>(get_figure()) returned None, and None doesn't have methods
>
>Something isn't set up right, but you'll have to trace that through.



Do you think the following statement is correct?

ax1 = row.plot( fontsize=font_size, 
    linewidth=line_width, 
    markersize=marker_size, 
    marker='o', 
    title='Raw values', 
    label=cnt, 
    ax=axes[0] )
ax1.set_ylabel( yax_label, fontsize=font_size )


As you can see I put the result of plot() to ax1 and then use some functions, 
e.g. set_ylabel().

On the other hand, I have specified `label` and `ax` in plot(), too.



Regards,
Mahmood

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: get_axes not present?

2021-11-18 Thread Mats Wichmann

On 11/18/21 02:49, Mahmood Naderan via Python-list wrote:


   File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 903, in _get_subplots
     ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, 
Subplot)
AttributeError: 'NoneType' object has no attribute 'get_axes'




I guess there is a mismatch between versions. Is there any workaround for that?


It's not saying get_axes doesn't exist because of version skew, it's 
saying that the object returned by the call to the left of it 
(get_figure()) returned None, and None doesn't have methods


Something isn't set up right, but you'll have to trace that through.

--
https://mail.python.org/mailman/listinfo/python-list


get_axes not present?

2021-11-18 Thread Mahmood Naderan via Python-list
Hi
I am using the following versions


>>> import matplotlib
>>> print(matplotlib. __version__)
3.3.4
>>> import pandas as pd
>>> print(pd.__version__)
1.2.3
>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)



In my code, I use axes in Pandas plot() like this (note that I omit some 
variables in this snippet to highlight the problem):



def plot_dataframe(df, cnt, axes):
    plt.subplot(2, 1, 1)
    ax1 = row.plot( fontsize=font_size, linewidth=line_width, 
markersize=marker_size, marker='o', title='Raw values', label=cnt, ax=axes[0] )



def plot_kernels(my_dict2):
    fig,axes = plt.subplots(2,1, figsize=(20, 15))
    should_plot = plot_dataframe(df, cnt, axes=axes)
    for ax in axes:
    ax.legend()
    plt.show()



However, I get this error:


Traceback (most recent call last):
  File "process_csv.py", line 174, in 
    plot_kernels( my_dict2 )
  File "process_csv.py", line 62, in plot_kernels
    should_plot = plot_dataframe(df, cnt, axes=axes)
  File "process_csv.py", line 34, in plot_dataframe
    ax1 = row.plot( fontsize=font_size, linewidth=line_width, 
markersize=marker_size, marker='o', title='Raw values', label=cnt, ax=axes[0] )
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_core.py", 
line 955, in __call__
    return plot_backend.plot(data, kind=kind, **kwargs)
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/__init__.py",
 line 61, in plot
    plot_obj.generate()
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 283, in generate
    self._adorn_subplots()
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 483, in _adorn_subplots
    all_axes = self._get_subplots()
  File 
"/home/mahmood/.local/lib/python3.8/site-packages/pandas/plotting/_matplotlib/core.py",
 line 903, in _get_subplots
    ax for ax in self.axes[0].get_figure().get_axes() if isinstance(ax, Subplot)
AttributeError: 'NoneType' object has no attribute 'get_axes'




I guess there is a mismatch between versions. Is there any workaround for that?




Regards,
Mahmood
-- 
https://mail.python.org/mailman/listinfo/python-list