Show a bar chart with only one series

日本語のページ

This page explains how to display a simple bar graph with only one series.

Execution result of a program that displays a bar chart

1. Create the source data for the chart

Enter the source data for the chart into an Excel worksheet.

As shown in the image below, enter the values ​​to be used as labels for the X-axis and the values ​​to be displayed as a bar chart.

Example of source data for bar chart

2. Adding blocks

Add the minimum necessary blocks by following the steps on the "Create and show chart" page.

Then, add a block to display a bar chart between the chart initialization and chart display blocks.

Block to display bar chart

This block is long horizontally, so it may be difficult to use if the screen width is narrow.

In that case, right-click the block and click "External input" in the menu to change it to a vertical shape.
You can also right-click a vertical block and click "Inline Input" in the menu to change it to a horizontal one.

3. Setting the source data for the chart

Use the cell range specification block in the "Excel" - "Cells" group to specify the cell range containing the data that will be the source of the chart with the "X" and "Y" parameters.

Block for specifying cell range

If you have entered the item name in the first row of the data, you can also enter the item name in the cell range with the "Y" parameter.

4. Formatting

You can set the format of the bar chart using parameters such as "Line width" and "Line type" for creating a bar chart.
The "Label" parameter specifies the label to be added to the bar chart series.
If you also include the item name in the cell range in the "Y" parameter, drag the "first value of Y" block in the "matplotlib" - "General chart" group to the "Label" parameter.

First Y value

5. Example

Assume the data has been entered into Excel as in the example above.

Example of source data for bar chart

In this case, specify cells A2 to A6 for the "X" parameter.

Specify cells B1 to B6 for the "Y" parameter, including the first item name.

In addition, drag the "First Y value" block to the "Label" parameter.

Example of drawing a bar chart with one series

When you run this program, you will see the graph at the top of this page.

The file for this example can be downloaded from here.
The Excel data file used in this example can also be downloaded from here.
Before running this example, open the data file in Excel.