During a BLISS session users may create data (other than scan data) that needs to be displayed graphically. Flint offers a collection of different type of plots (curve, scatter, image...) so user can select the one that best fits with the data to be displayed.
During a BLISS session, users may create data (other than scan data) that needs
to be displayed graphically. Flint offers a collection of different type of
plots (curve, scatter, image...) so user can select the one that best fits
with the data to be displayed.
## Plot types
## Basic plot display
The **bliss.common.plot** module offers several types of plot:
A generic display is provided through the BLISS `plot` command.
### Curve plot
This the data dimensionality to select and display a plot.
`class CurvePlot(BasePlot)`
This can be convenient for basic display.
* plotting of one or several 1D data as curves
* Optional x-axis data can be provided
* the plot is created using `plot_curve`

```python
# Display a list (as a single curve using index as x-axis)
plot([1,2,3,1,2,3])
importnumpy
# Display a 1D data (as a single curve using index as x-axis)
array=numpy.array([1,2,3,1,2,3])
plot(array)
# Display a 2D data (as an image)
image=numpy.array([[1,2,3],[1,2,3],[1,2,3]])
plot(image)
# Display a 3D data (as a stack of images)
cube=numpy.arange(1000)
cube.shape=10,10,10
plot(cube)
```
## Create a plot
To use more features another way is provided.
First a plot have to be created from the Flint.
The first argument (here `curve`) is used to select the kind of expected plot.
See the following documentation for example for each kind.
```python
f=flint()
p=f.get_plot("curve")
```
Other arguments are available to edit some behavior of this plot.
A title can be specified, a unique name can be set to reuse plots instead of
creating a new one. The plot can be closeable (default is true) or selected
by default at the creation (default is false).
```python
p=f.get_plot("curve",
name="My plot title",
unique_name="myplot42",
closeable=True,
selected=True)
```
## 1D plot / curve plot
The main plot is a curve plot.
It can be used to display several 1D data as curves.
```python
importnumpy
frombliss.commonimportplotasplot_mdl
# Function
# Create the plot
f=flint()
p=f.get_plot("curve",name="My plot")
# Create data
t=numpy.linspace(0,10*numpy.pi,100)
y=numpy.sin(t)
plot_mdl.plot_curve(data=y,name="My sin")
s=numpy.sin(t)
c=numpy.cos(t)
# Update the plot
p.add_curve(t,c,legend="aaa")# the legend have to be unique
p.add_curve(t,s,legend="bbb")
# Clean up the plot
p.clean_data()
```
This also can be used to display parametric functions
All the above plot types provide the same interface. They take the data
as an argument and return a plot. Here's an example on how to display a cosine wave in a curve plot.
```python
xx=numpy.linspace(0,4*3.14,50)
yy=numpy.cos(xx)
plot(yy,name="Plot 0")
```
After the execution of these commands, Flint interface will show up, with a main tab named "Plot 0" (below application's main menu) with a plot with a cosine wave on it.

We can add extra keyword arguments that are forwarded to silx. and recover a plot object to interact with it lately:
```python
p=plot(mydata,xlabel='A',ylabel='b')
```
From then on, all the interaction with the corresponding plot window goes
through the plot object `p`. For instance, it provides a ``plot`` method
to add and display extra data:
```python
p.plot(some_extra_data,yaxis='right')
```
## Advanced interface
## Extra commands
To be able to reuse a plot you can use the function from Flint object.
Based on the unique name, this will create a plot only if needed, else it will
retrieve the existing plot.
Plots provide few extra commands.
```python
# Create a plot
f=flint()
p=f.get_plot("plot1d","My title","uniquename999")
p=f.get_plot(plot_class="plot1d",name="My plot")
```
For a finer control over the plotted data, the data management is
separated from the plot management. In order to add more data to
the plot, use the following interface:
The plot life cycle can be checked and changed with this commands:
```python
p.add_data(cos_data,field='cos')
ifp.is_open():
p.close()
```
This data is now identified using its field, ``'cos'``. A dict or
a structured numpy array can also be provided. In this case,
the fields of the provided data structure are used as identifiers:
Set the focus on a specific plot can be set the following way:
```python
p.add_data({'cos':cos_data,'sin':sin_data})
p.focus()
```
Note that ``add_data`` does not plot the data on the chart. The plot selection is then done through the ``select_data`` method.
For a curve plot, the expected arguments are the names of the data
to use for X and Y:
A plot can be exported to the logbook this way:
```python
p.select_data('sin','cos')
p.export_to_logbook()
```
Again, the extra keyword arguments will be forwarded to silx: