docstr: Add scalar data to Visdom. Plots the values in a plot titled
     {main_tag}-{tag}.
  
  Args:
      tag (string): Data identifier
      scalar_value (float or string/blobname): Value to save
      global_step (int): Global step value to record
      main_tag (string): Data group identifier
docstr_tok: ["Add","scalar","data","to","Visdom",".","Plots","the","values","in","a","plot","titled","{","main_tag","}","-","{","tag","}",".","Args",":","tag","(","string",")",":","Data","identifier","scalar_value","(","float","or","string\/blobname",")",":","Value","to","save","global_step","(","int",")",":","Global","step","value","to","record","main_tag","(","string",")",":","Data","group","identifier"]
code: def add_scalar(
      self, tag, scalar_value, global_step=None, main_tag="default"
  ):
      """Add scalar data to Visdom. Plots the values in a plot titled
         {main_tag}-{tag}.
  
      Args:
          tag (string): Data identifier
          scalar_value (float or string/blobname): Value to save
          global_step (int): Global step value to record
          main_tag (string): Data group identifier
      """
      if self.scalar_dict.get(main_tag) is None:
          self.scalar_dict[main_tag] = {}
      exists = self.scalar_dict[main_tag].get(tag) is not None
      self.scalar_dict[main_tag][tag] = (
          self.scalar_dict[main_tag][tag] + [scalar_value]
          if exists
          else [scalar_value]
      )
      plot_name = "{}-{}".format(main_tag, tag)
      # If there is no global_step provided, follow sequential order
      x_val = (
          len(self.scalar_dict[main_tag][tag])
          if not global_step
          else global_step
      )
      if exists:
          # Update our existing Visdom window
          self.vis.line(
              X=make_np(x_val),
              Y=make_np(scalar_value),
              name=plot_name,
              update="append",
              win=self.windows[plot_name],
          )
      else:
          # Save the window if we are creating this graph for the first time
          self.windows[plot_name] = self.vis.line(
              X=make_np(x_val),
              Y=make_np(scalar_value),
              name=plot_name,
              opts={
                  "title": plot_name,
                  "xlabel": "timestep",
                  "ylabel": tag,
              },
          )
  
imports: import gc
  import numpy
  import math
  import json
  import time
  from .summary import compute_curve
  from .utils import figure_to_image
  from .x2num import make_np
label_desc: Use image node_id 3 for calling the VisdomWriter obj's underlying member method code with example usage: obj.add_scalar(tag, scalar_value, global_step, main_tag) without return types