<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/summary/tb_summary.py#L243-L299) |

Write a scalar summary.

    tf.summary.scalar(
        name, data, step=None, description=None
    )

### Used in the notebooks

| Used in the tutorials |
|---|
| - [pix2pix: Image-to-image translation with a conditional GAN](https://www.tensorflow.org/tutorials/generative/pix2pix) - [TensorBoard Scalars: Logging training metrics in Keras](https://www.tensorflow.org/tensorboard/scalars_and_keras) - [Get started with TensorBoard](https://www.tensorflow.org/tensorboard/get_started) - [Research tools](https://www.tensorflow.org/quantum/tutorials/research_tools) - [Migrating tf.summary usage to TF 2.x](https://www.tensorflow.org/tensorboard/migrate) |

See also [`tf.summary.image`](https://www.tensorflow.org/api_docs/python/tf/summary/image), [`tf.summary.histogram`](https://www.tensorflow.org/api_docs/python/tf/summary/histogram),
[`tf.summary.SummaryWriter`](https://www.tensorflow.org/api_docs/python/tf/summary/SummaryWriter).

Writes simple numeric values for later analysis in TensorBoard. Writes go to
the current default summary writer. Each summary point is associated with an
integral `step` value. This enables the incremental logging of time series
data. A common usage of this API is to log loss during training to produce
a loss curve.

#### For example:

    test_summary_writer = tf.summary.create_file_writer('test/logdir')
    with test_summary_writer.as_default():
        tf.summary.scalar('loss', 0.345, step=1)
        tf.summary.scalar('loss', 0.234, step=2)
        tf.summary.scalar('loss', 0.123, step=3)

Multiple independent time series may be logged by giving each series a unique
`name` value.

See [Get started with
TensorBoard](https://www.tensorflow.org/tensorboard/get_started)
for more examples of effective usage of [`tf.summary.scalar`](https://www.tensorflow.org/api_docs/python/tf/summary/scalar).

In general, this API expects that data points are logged with a monotonically
increasing step value. Duplicate points for a single step or points logged out
of order by step are not guaranteed to display as desired in TensorBoard.

<br />

<br />

<br />

| ## Arguments ||
|---|---|
| `name` | A name for this summary. The summary tag used for TensorBoard will be this name prefixed by any active name scopes. |
| `data` | A real numeric scalar value, convertible to a `float32` Tensor. |
| `step` | Explicit `int64`-castable monotonic step value for this summary. If omitted, this defaults to [`tf.summary.experimental.get_step()`](https://www.tensorflow.org/api_docs/python/tf/summary/experimental/get_step), which must not be None. |
| `description` | Optional long-form description for this summary, as a constant `str`. Markdown is supported. Defaults to empty. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| True on success, or false if no summary was written because no default summary writer was available. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | if a default writer exists, but no step was provided and [`tf.summary.experimental.get_step()`](https://www.tensorflow.org/api_docs/python/tf/summary/experimental/get_step) is None. |

<br />