Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 配置文件_Python_Python 3.x_Matplotlib_Configuration - Fatal编程技术网

Python 配置文件

Python 配置文件,python,python-3.x,matplotlib,configuration,Python,Python 3.x,Matplotlib,Configuration,是否可以将这样的内容写入.cfg文件(=字符串形式的ale) 在另一个文件中查找此文件 plt.plot([1, 10],[2, 2], cfg['styles']['help_lines']) 建议后编辑: plt.rcParams['text.latex.preamble']=[r"\usepackage{lmodern}"] params = {'text.usetex' : True, 'font.size' : 11, 'font.family

是否可以将这样的内容写入.cfg文件(=字符串形式的ale)

在另一个文件中查找此文件

plt.plot([1, 10],[2, 2], cfg['styles']['help_lines'])
建议后编辑:

plt.rcParams['text.latex.preamble']=[r"\usepackage{lmodern}"]
params = {'text.usetex' : True,
          'font.size' : 11,
          'font.family' : 'lmodern',
          'text.latex.unicode': True,
          }
plt.rcParams.update(params)
如何将其写入myconfig.py以及如何将其包含到script.py?

您看过该模块了吗

以下是您可以做的:

  • config.ini

    [styles] 
    help_lines = silver
    c = silver
    ls = dashed
    
  • 用法:

    cfg = configparser.ConfigParser()
    cfg.read('/path/to/config.ini')
    
    print(cfg['styles']['help_lines'])
    # silver
    

    • 请注意,可以使用python文件来实现这一点

      myconfig.py

      class styles:
          helper_lines = dict(c  = "silver",
                              ls = "dashed")
      
      import myconfig as cfg
      import matplotlib.pyplot as plt
      
      plt.plot([1,2,3], **cfg.styles.helper_lines)
      plt.show()
      
      script.py

      class styles:
          helper_lines = dict(c  = "silver",
                              ls = "dashed")
      
      import myconfig as cfg
      import matplotlib.pyplot as plt
      
      plt.plot([1,2,3], **cfg.styles.helper_lines)
      plt.show()
      

      谢谢你,你能帮我修改我的问题吗?