<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Publication ready figures with matplotlib and Jupyter notebook
A very convenient workflow to analyze data and create figures that can be used in various ways for publication is to use the IPython Notebook or Jupyer notebook in combination with matplotlib. I faced the problem that one often needs different file formats for different kind of publications, such as on a webpage or in a paper. For instance, to put the figure on a webpage, most softwares support only png or jpg formats, so that a fixed resolution must be provided. On the other hand, a scalable figure format can be scaled as needed and when putting it into a pdf document, there won't be artifacts when zooming into the figure. In this blog post, I'll provide a small function that saves the matplotlib figure to various file formats, which can then be used where needed.
Creating a simple plot
A simple plot can be created within an ipython notebook with
Step1:  Creating a quatratic plot
Step3:  Save the figure
The previous figure can be saved with calling matplotlib.pyplot.savefig and matplotlib will save the figure in the output format based on the extension of the filename. To save to various formats, one would need to call this function several times or instead define a new function that can be included as boilerplate in the first cell of a notebook such as
Step4:  And it can be easily saved with
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import seaborn as snb
import numpy as np
import matplotlib.pyplot as plt
Explanation: Publication ready figures with matplotlib and Jupyter notebook
A very convenient workflow to analyze data and create figures that can be used in various ways for publication is to use the IPython Notebook or Jupyer notebook in combination with matplotlib. I faced the problem that one often needs different file formats for different kind of publications, such as on a webpage or in a paper. For instance, to put the figure on a webpage, most softwares support only png or jpg formats, so that a fixed resolution must be provided. On the other hand, a scalable figure format can be scaled as needed and when putting it into a pdf document, there won't be artifacts when zooming into the figure. In this blog post, I'll provide a small function that saves the matplotlib figure to various file formats, which can then be used where needed.
Creating a simple plot
A simple plot can be created within an ipython notebook with:
Loading matplotlib and setting up ipython notebook to display the graphics inline:
End of explanation
def create_plot():
    x = np.arange(0.0, 10.0, 0.1)
    plt.plot(x, x**2)
    plt.xlabel("$x$")
    plt.ylabel("$y=x^2$")
    
create_plot()
plt.show()
Explanation: Creating a quatratic plot:
End of explanation
def save_to_file(filename, fig=None):
    Save to @filename with a custom set of file formats.
    
    By default, this function takes to most recent figure,
    but a @fig can also be passed to this function as an argument.
    
    formats = [
                "pdf",
                "eps",
                "png",
                "pgf",
              ]
    if fig is None:
        for form in formats:
            plt.savefig("%s.%s"%(filename, form))
    else:
        for form in formats:
            fig.savefig("%s.%s"%(filename, form))
Explanation: Save the figure
The previous figure can be saved with calling matplotlib.pyplot.savefig and matplotlib will save the figure in the output format based on the extension of the filename. To save to various formats, one would need to call this function several times or instead define a new function that can be included as boilerplate in the first cell of a notebook such as:
End of explanation
create_plot()
save_to_file("simple_plot")
Explanation: And it can be easily saved with:
End of explanation
<END_TASK>