Hi Bob,
Sorry for the lack of github action. I have been coding lots, but have not pushed stuff for a few reasons.
I had a working version of the plotting, including the elusive floating axis. It looked really cool and was pretty happy with myself. But I also realised I coded quickly, focused on determining whether what I wanted to do was actually possible. After getting the code to work, it was clear it was quite a mess, would not make sense to anyone else, and would be difficult to maintain.
So I have spent the last few nights refactoring the code. It has been difficult because making plots of this type is a lot of linear coding with if
conditionals (e.g. if add_color == True: ...
; if remove_axis == True: ...
). When this is combined with some additional data processing, the codes gets long.
I have added a mixin class to help, and have also broken things down somewhat. However, I have come across a few issues I would like to get your thoughts on.
I read somewhere that is it not great coding practice to add attributes to a class outside the init method. Do you agree with this? What would be bad about such a practice?
I now have a Figure
mixin class that is inherited by two other figure-related classes. The only method that is actually public in any of these class (public in the sense that a user might need to call them) in Figure .plot()
. All the other methods break down the steps that need to go into making the figure. For examples, here is a method I flagged to discuss. The actual code needs work. the thing I want to highlight are the inputs and return value.
![b](https://user-images.githubusercontent.com/12129388/91978471-81019380-ed67-11ea-83fc-6859c48b776c.png)
The method returns a value, but not to the user/caller. The method is called by another method of the same class. In theory, I could skip passing the inputs and returning of values if I simply assigned newly computed values that are required elsewhere to self.
In case that was not clear... I the above method I need to computer the optimal_yticks
and use them to identify a few things and then also use them to actually set the y-ticks for the plot. By returning this value I now have to pass it around to all the method that want to use it. Would it not be simpler to make it into an attribute self.optimal_yticks = optimal_yticks
?
I have another question about when to make something a method in a class vs a stand alone function (or maybe even a standalone smaller class). With Spike2py things were relatively clear. However, with this plotting stuff, everything could be done with a bunch of small functions located in separate modules, or they could be part of a class.
What I struggle with is that my original Figure
class started to have way to many methods, some of which were not focused on generating the figure but rather computations to figure out where the floating axis had to be positioned.
It was handy to have the computation method in the Figure
class because it could access all the attributes. But it was rather long and made for a confused class (it was definitely doing more than one thing).
I realise this hypothetical talk might be hard to grasp, and you would much rather look at the code and comment. I totally understand! I will try to get the code working again in the next day or two (my refactoring has currently left the code broken and I am mess as I struggle to find the best approach), and push it so that you can have a look.