Python Forum
What does that angle brackets mean?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What does that angle brackets mean?
#1
Hey, I am learning some numpy, matplotlib and pandas stuff.
And I wondered about some angle brackets in the output of this code (housing is a pandas dataframe):

%matplotlib inline
import matplotlib.pyplot as plt
hist_diagram = housing.hist(bins=50, figsize=(20, 15))
print(hist_diagram)
The output is:

Output:
[[<AxesSubplot:title={'center':'longitude'}> <AxesSubplot:title={'center':'latitude'}> <AxesSubplot:title={'center':'housing_median_age'}>] [<AxesSubplot:title={'center':'total_rooms'}> <AxesSubplot:title={'center':'total_bedrooms'}> <AxesSubplot:title={'center':'population'}>] [<AxesSubplot:title={'center':'households'}> <AxesSubplot:title={'center':'median_income'}> <AxesSubplot:title={'center':'median_house_value'}>]]
Can you tell me, what that angle brackets mean?

Thanks a lot.
Reply
#2
It means nothing.

When printing an object, Python calls a special method named __repr__() or __str__(). In your example it would call __repr__() because that is the one used when printing a list of objects. The author of the code can format the str any way they seem fit. The author of this matplotlib code decided to use the class name followed by some attributes, surrounded by angle brackets.
Reply
#3
Hi,

thanks for your answer.

But I have another question. I used mro() to see the whole inheritance of AxesSubplot. And I wondered about "_subplots", "_base" and "_axes":

%matplotlib inline
import matplotlib.pyplot as plt
hist_diagram = housing.hist(bins=50, figsize=(20, 15))
print(type(hist_diagram[0][0]).mro())
Output:
[<class 'matplotlib.axes._subplots.AxesSubplot'>, <class 'matplotlib.axes._subplots.SubplotBase'>, <class 'matplotlib.axes._axes.Axes'>, <class 'matplotlib.axes._base._AxesBase'>, <class 'matplotlib.artist.Artist'>, <class 'object'>]
In the docs of matplotlib I can see there is a class named "matplotlib.axes.SubplotBase", but not a class names "matplotlib.axes._subplots.SubplotBase". What does this _subplots stand for?
Reply
#4
Python doesn't have any kind of private or protected access for object attributes. Everything is public. Names that start with underscore are like a private attribute. It does not provide any real protection, just a convention warning the user that this is for internal use. It is not part of the api and may change without notice.
Reply
#5
Thanks for your answer.

I know, what the _ means. My problem is, that I don't find _subplots in matplotlib.axes.
Reply
#6
Why is that a problem? You are being warned that this is an internal detail that is not part of the API. Why do you care what they are?

They are probably Python wrappers around some C++ libraries,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  semantics of comma inside array brackets usercat123 2 1,367 Apr-23-2022, 09:08 AM
Last Post: usercat123
  angular servo motor can't keep up with angle inputs taher50 1 2,287 Mar-10-2018, 07:18 PM
Last Post: taher50

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020