Skip to content

Commit

Permalink
Replaced plot_graph with print_figure
Browse files Browse the repository at this point in the history
  • Loading branch information
karelvaculik committed Sep 11, 2023
1 parent 8f45bbc commit f5ba885
Show file tree
Hide file tree
Showing 32 changed files with 255 additions and 2,429 deletions.
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Changelog

## 1.0.0 (2023-09-02)
## 1.0.0 (2023-09-11)

- Updated to newer versions of optional dependencies.
- Created documentation at readthedocs.
- Added new text elements `div()` and `span()`. Added new parameters to HTML elements - in particular `cl` and `attrs`.
- Deprecated `print_html()` function. New `print()` should be used instead.
- Deprecated `print_code()` function. New `print_source_code()` should be used instead.
- Replaced `print_html()` function with `print()`.
- Replaced `print_code()` function with `print_source_code()`.
- Replaced `plot_graph()` with `print_figure()`.
- Removed `plot_multi_graph`.
- Replaced code-prettify with highlight.js for code blocks.
- `print_h1`, ..., `print_h6` functions can now take a `Reference` object.
- Added `--config-path` CLI option, changed how `pyreball-generate-config` command works and how the config paths are
handled.
- Updated CLI arguments and config parameters for tables and figures.
- Updated to newer versions of 3rd party dependencies for example.
- Created documentation at readthedocs.

## 0.1.1 (2021-09-14)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pb.print_table(df, caption="A data table.")
fig, ax = plt.subplots()
sns.lineplot(x="x", y="y", ax=ax, data=df)
ax.set(xlabel="x", ylabel="y")
pb.plot_graph(fig, caption="The first plot.")
pb.print_figure(fig, caption="The first plot.")
```

In this particular example, we are using a few 3rd party packages, so let's install them too:
Expand Down
42 changes: 21 additions & 21 deletions docs/configuration.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/examples/example_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pb.print_div(
"Pyreball has many features, among others:",
pb.ulist(
"Creating plots.",
"Creating charts.",
"Sortable and scrollable tables.",
f'Basic text formatting such as {pb.em("emphasis")}.',
f'Also {pb.link("hyperlinks", "https://www.python.org/")}.',
Expand Down
6 changes: 2 additions & 4 deletions docs/examples/example_init_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import pyreball as pb
import seaborn as sns

pb.set_title("Tables and Plots")
pb.set_title("Tables and Figures")

# Print a table
df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 6, 5]})
pb.print_table(df, caption="A data table.")

# Plot a graph
fig, ax = plt.subplots()
sns.lineplot(x="x", y="y", ax=ax, data=df)
ax.set(xlabel="x", ylabel="y")
pb.plot_graph(fig, caption="A line plot.")
pb.print_figure(fig, caption="A line chart.")
2 changes: 1 addition & 1 deletion docs/examples/plotting_bokeh.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
fig = figure(x_range=df["x"])
fig.vbar(x="x", top="y", width=0.9, source=ColumnDataSource(data=df))
fig.add_tools(HoverTool(tooltips=[("x", "@x"), ("y", "@y")]))
pb.plot_graph(fig, caption="Bokeh barchart.")
pb.print_figure(fig, caption="Bokeh barchart.")
2 changes: 1 addition & 1 deletion docs/examples/plotting_matplotlib_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
plt.bar([1, 2, 3], [4, 3, 6])
plt.xlabel("x")
plt.ylabel("y")
pb.plot_graph(
pb.print_figure(
fig,
caption="Matplotlib barchart as png.",
matplotlib_format="png",
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/plotting_matplotlib_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
plt.bar([1, 2, 3], [4, 3, 6])
plt.xlabel("x")
plt.ylabel("y")
pb.plot_graph(
pb.print_figure(
fig,
caption="Matplotlib barchart as svg.",
matplotlib_format="svg",
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/plotting_plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 3, 6]})

fig = px.bar(df, x="x", y="y")
pb.plot_graph(fig, caption="Plotly graph.")
pb.print_figure(fig, caption="Plotly chart.")
2 changes: 1 addition & 1 deletion docs/examples/plotting_seaborn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
fig, ax = plt.subplots()
sns.barplot(x="x", y="y", data=df, ax=ax, color=sns.xkcd_rgb["windows blue"])
ax.set(xlabel="x", ylabel="y")
pb.plot_graph(
pb.print_figure(
fig,
caption="Seaborn barchart as png.",
matplotlib_format="png",
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/plotting_vega_altair.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
height=400,
)
)
pb.plot_graph(fig, caption="Vega-Altair barchart.")
pb.print_figure(fig, caption="Vega-Altair barchart.")
4 changes: 2 additions & 2 deletions docs/examples/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pyreball as pb
import seaborn as sns

pb.set_title("References to Plots and Tables")
pb.set_title("References to Figures and Tables")

ref_ch_1 = pb.Reference()

Expand Down Expand Up @@ -47,7 +47,7 @@
fig, ax = plt.subplots()
sns.scatterplot(x="x", y="y", ax=ax, data=df)
ax.set(xlabel="x", ylabel="y")
pb.plot_graph(fig, caption="A plot with a reference.", reference=img_reference)
pb.print_figure(fig, caption="A figure with a reference.", reference=img_reference)

pb.print_div(
f"Note that you can use the references in your text multiple times, "
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/references_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

ref = pb.Reference("My Table")
pb.print(f"It is possible to create a link {ref} before the target...")
pb.print_table(pd.DataFrame({'a': [1, 2], 'b': [3, 4]}), reference=ref)
pb.print_table(pd.DataFrame({"a": [1, 2], "b": [3, 4]}), reference=ref)
pb.print(f"and also link {ref} after the target.")
pb.print(f"It is also possible to create {ref('link with custom text')}.")
3 changes: 1 addition & 2 deletions docs/examples/text_utils_formatting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pyreball as pb

pb.print(
f"This sentence contains both {pb.bold('bold')} "
f"and {pb.em('emphasized')} text."
f"This sentence contains both {pb.bold('bold')} " f"and {pb.em('emphasized')} text."
)
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Pyreball is a Python reporting tool that generates HTML reports from Python scri

Main features:

- Plots in [Vega-Altair](https://altair-viz.github.io/index.html), [Plotly](https://plotly.com/), [Bokeh](https://bokeh.org/), and [Matplotlib](https://matplotlib.org/) (and thus also [Seaborn](https://seaborn.pydata.org/) etc.).
- Charts in [Vega-Altair](https://altair-viz.github.io/index.html), [Plotly](https://plotly.com/), [Bokeh](https://bokeh.org/), and [Matplotlib](https://matplotlib.org/) (and thus also [Seaborn](https://seaborn.pydata.org/) etc.).
- Interactive tables based on [DataTables](https://datatables.net/) library and created from [pandas DataFrame](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html).
- Basic text formatting such as headings, emphasis, and lists.
- Hyperlinks, references and table of contents.
Expand Down Expand Up @@ -39,23 +39,23 @@ pyreball report.py

<iframe style="border:2px solid;" src="examples/example_init.html" height="300" width="100%" title="Iframe Example"></iframe>

## Adding Tables and Plots
## Adding Tables and Figures

The core functionality of `pyreball` does not require any 3rd party dependencies.
However, it is possible to generate other types of elements with the help of libraries such
as [pandas](https://pandas.pydata.org/) or [seaborn](https://seaborn.pydata.org/).

Let's create another python script called `report_plot.py`:
Let's create another python script called `report_chart.py`:

{{ inline_source("docs/examples/example_init_deps.py") }}

Install `pandas` and `seaborn`, then run `pyreball`:

```
pip install pandas seaborn
pyreball report_plot.py
pyreball report_chart.py
```

`report_plot.html` should look like this:
`report_chart.html` should look like this:

<iframe style="border:2px solid;" src="examples/example_init_deps.html" height="800" width="100%" title="Iframe Example"></iframe>
22 changes: 11 additions & 11 deletions docs/plotting.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ Pyreball currently supports plotting figures created
by [Matplotlib](https://matplotlib.org/), [Seaborn](https://seaborn.pydata.org/), [Vega-Altair](https://altair-viz.github.io/index.html),
[Plotly](https://plotly.com/), and [Bokeh](https://bokeh.org/).

There is a single function [`plot_graph()`](../api/pyreball_html/#pyreball.html.plot_graph) for all these libraries.
There is a single function [`print_figure()`](../api/pyreball_html/#pyreball.html.print_figure) for all these libraries.
Similarly to [`print_table()`](../api/pyreball_html/#pyreball.html.print_table), it uses
parameters `caption`, `align`, `caption_position` and `numbered` with the same meaning.
In contrast to table captions, the default position of plot captions is `bottom`.
In contrast to table captions, the default position of figure captions is `bottom`.

## Matplotlib

When plotting with Matplotlib, it is necessary to create a figure object and pass it
to [`plot_graph()`](../api/pyreball_html/#pyreball.html.plot_graph).
to [`print_figure()`](../api/pyreball_html/#pyreball.html.print_figure).

In case of Matplotlib, a user can select the format of the plot via `matplotlib_format` parameter: either `"png"`
In case of Matplotlib, a user can select the format of the figure via `matplotlib_format` parameter: either `"png"`
or `"svg"`.
In case of `"svg"`, it is also possible to choose whether the plot should be embedded into the HTML file or saved into a
separate file and referenced in the HTML file by setting `embedded` accordingly.
Plots in `"png"` format cannot be embedded into the HTML file.
In case of `"svg"`, it is also possible to choose whether the figure should be embedded into the HTML file
or saved into a separate file and referenced in the HTML file by setting `embedded` accordingly.
Figures in `"png"` format cannot be embedded into the HTML file.

When the plot is stored into a file, the file is saved in a directory with name equal to the filename stem of the HTML
When the figure is stored into a file, the file is saved in a directory with name equal to the filename stem of the HTML
file. For example, for HTML file `report.html`, the image file will be stored in directory `report`.

The following code shows an example of a bar chart created with Matplotlib and stored in a `"png"` format.
Expand All @@ -29,7 +29,7 @@ The following code shows an example of a bar chart created with Matplotlib and s

<iframe style="border:2px solid;" src="../examples/plotting_matplotlib_png.html" height="540" width="100%" title="Iframe Example"></iframe>

The next example shows the same plot, but embedded directly into the HTML document in `"svg"` format.
The next example shows the same chart, but embedded directly into the HTML document in `"svg"` format.

{{ inline_source("docs/examples/plotting_matplotlib_svg.py") }}

Expand Down Expand Up @@ -58,15 +58,15 @@ e.g. `altair.ConcatChart`, `altair.HConcatChart`.

## Plotly

Pyreball supports interactive plots created by Plotly, too.
Pyreball supports interactive charts created by Plotly, too.

{{ inline_source("docs/examples/plotting_plotly.py") }}

<iframe style="border:2px solid;" src="../examples/plotting_plotly.html" height="540" width="100%" title="Iframe Example"></iframe>

## Bokeh

Another library for plotting interactive plots supported by Pyreball is Bokeh.
Another library for plotting interactive charts supported by Pyreball is Bokeh.

{{ inline_source("docs/examples/plotting_bokeh.py") }}

Expand Down
6 changes: 3 additions & 3 deletions docs/references.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class.
Specifically, one can create a reference object by calling `pb.Reference()`.
This object can be then passed to a function that creates a
table ([`print_table()`](../api/pyreball_html/#pyreball.html.print_table)),
a plot ([`plot_graph()`](../api/pyreball_html/#pyreball.html.plot_graph)), or
a figure ([`print_figure()`](../api/pyreball_html/#pyreball.html.print_figure)), or
a heading ([`print_h1()`](../api/pyreball_html/#pyreball.html.print_h1), ...,
[`print_h6()`](../api/pyreball_html/#pyreball.html.print_h6)).
Each such function then creates a target for the link.
Expand All @@ -31,8 +31,8 @@ a parameter that is used to override the default link
text.

When default link text is not provided through the constructor, Pyreball uses table numbers as texts for links pointing
to tables. The same is applied for links pointing to plots. In case of headings, the default link text would be the text
of the heading itself.
to tables. The same is applied for links pointing to figures.
In case of headings, the default link text would be the text of the heading itself.

The artificial example below demonstrates some of these features.

Expand Down
Loading

0 comments on commit f5ba885

Please sign in to comment.