I want to create a module for a custom plot drawing for my scientific data, but I do not know how to pass an argument of type (*arg2,**kwarg2)
to a method.
Here is the relevant code:
import numpy as np
import matplotlib.pyplot as plt
# class of figures for channel flow
# with one subfigure
class Homfig:
# *args: list of plot features for ax1.plot
# (xdata,ydata,str linetype,str label)
# **kwargs: list of axes features for ax1.set_$(STH)
# possible keys:
# title,xlabel,ylabel,xlim,ylim,xscale,yscale
def __init__(self,*args,**kwargs):
self.args = args
self.kwargs = kwargs
self.fig = plt.figure()
self.ax = self.fig.add_subplot(111)
for key, val in self.kwargs.iteritems():
getattr(self.ax,'set_'+key)(val)
def hdraw(self):
for arg in self.args:
self.ax.plot(*arg)
leg = self.ax.legend(loc=4)
The problem is that arg
is itself a tuple like (*agr2,**kwarg2)
and when I call
self.ax.plot(*arg)
it does not see named variables.
Function hdraw
should operate on the input it got in *args
from init, and data for plot lines are passed in arg
.
How can I express that arg
consists of unnamed and named variables?
self.ax.plot
may be called more then once, when I want to have several lines (with different label
, linetype
, etc., in one plot.)
I call the module from other python script with:
meanfig = hfig.Homfig((datax,datay),title='test plot')
meanfig.hdraw()
How can I add features like label or linetype to the self.ax.plot, for example:
meanfig = hfig.Homfig((datax,datay,label="test_label",linetype ='o'),title='test plot')