# Plots

MecSimCalc supports the two most popular plotting libraries:

1. Matplotlib
2. Plotly

## Matplotlib​

Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python.

Visit matplotlib.org for full documentation on how to use Matplotlib:

Once your Matplotlib figure is ready to be displayed, convert it to a HTML string using the mecsimcalc library as follows:

### Code​

import matplotlib.pyplot as pltimport numpy as npimport mecsimcalc as mscdef main(inputs):    # Create matplotlib figure    x = np.arange(0, 2, 0.01)    y = 2*(np.cos(4*x))    plt.plot(x, y)    # Convert figure to html using msc.print_plot()    plot_html = msc.print_plot(plt)    return {"plot": plot_html}

### Output​

{{ outputs.plot }}

See Example 2 in the introduction section for a detailed example on using Matplotlib.

## Plotly​

Plotly's Python graphing library makes interactive, publication-quality graphs.

Visit plotly.com/python for full documentation on how to use Plotly:

Once your Plotly figure is ready to be displayed, convert it to a HTML string that can be embedded into the outputs step. As follows:

### Code​

import plotly.express as pximport pandas as pdimport numpy as npdef main(inputs):    # Create plotly figure    x = np.arange(0, 2, 0.01)    y = 2*(np.cos(4*x))    fig = px.line(x, y, title="Cosine")    # Convert figure to html using to_html()    plot_html = fig.to_html(include_plotlyjs=True, full_html=False)    return {"plot": plot_html}
caution

In .to_html(), include_plotlyjs must be set to True for the plot to be displayed.

### Output​

{{ outputs.plot }}