Allow setting margins individually in set_margins()
This commit is contained in:
		
							parent
							
								
									81ba2604ac
								
							
						
					
					
						commit
						a8e2ec73a5
					
				
					 1 changed files with 13 additions and 5 deletions
				
			
		
							
								
								
									
										18
									
								
								lib/plot.py
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								lib/plot.py
									
										
									
									
									
								
							|  | @ -15,9 +15,9 @@ class Paper: | |||
|             'left': 0 | ||||
|         } | ||||
|         self.set_margins(margins) | ||||
|          | ||||
| 
 | ||||
|     def set_margins(self, margins): | ||||
|     def set_margins(self, margins=None, top=None, right=None, bottom=None, | ||||
|                     left=None): | ||||
|         if isinstance(margins, int) or isinstance(margins, float): | ||||
|             self.margins['top'] = margins | ||||
|             self.margins['right'] = margins | ||||
|  | @ -40,9 +40,18 @@ class Paper: | |||
|                 self.margins['right'] = margins[1] | ||||
|                 self.margins['bottom'] = margins[2] | ||||
|                 self.margins['left'] = margins[3] | ||||
|         else: | ||||
|         elif margins is not None: | ||||
|             self.margins = margins | ||||
| 
 | ||||
|         if top is not None: | ||||
|             self.margins['top'] = top | ||||
|         if right is not None: | ||||
|             self.margins['right'] = right | ||||
|         if bottom is not None: | ||||
|             self.margins['bottom'] = bottom | ||||
|         if left is not None: | ||||
|             self.margins['left'] = left | ||||
| 
 | ||||
|     @property | ||||
|     def content_width(self): | ||||
|         return self.width - self.margins['left'] - self.margins['right'] | ||||
|  | @ -126,7 +135,6 @@ A6_PORTRAIT = Paper(105, 148, 8) | |||
| A6_LANDSCAPE = Paper(148, 105, 8) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| class Plotter: | ||||
| 
 | ||||
|     def __init__(self, paper, line_width=0, colour=[0, 0, 0, 1]): | ||||
|  | @ -308,4 +316,4 @@ class MultiPlotter(Plotter): | |||
| 
 | ||||
|     @property | ||||
|     def paper(self): | ||||
|         return self.plotters[0].paper | ||||
|         return self.plotters[0].paper | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue