MCPcopy
hub / github.com/Qiskit/qiskit / _plot_data

Function _plot_data

qiskit/visualization/counts_visualization.py:440–487  ·  view source on GitHub ↗

Generate the data needed for plotting counts. Args: data (list or dict): This is either a list of dictionaries or a single dict containing the values to represent (ex {'001': 130}) labels (list): The list of bitstring labels for the plot. number_to_keep (int)

(data, labels, number_to_keep, kind="counts")

Source from the content-addressed store, hash-verified

438
439
440def _plot_data(data, labels, number_to_keep, kind="counts"):
441 """Generate the data needed for plotting counts.
442
443 Args:
444 data (list or dict): This is either a list of dictionaries or a single
445 dict containing the values to represent (ex {'001': 130})
446 labels (list): The list of bitstring labels for the plot.
447 number_to_keep (int): The number of terms to plot and rest
448 is made into a single bar called 'rest'.
449 kind (str): One of 'counts' or 'distribution`
450
451 Returns:
452 tuple: tuple containing:
453 (dict): The labels actually used in the plotting.
454 (list): List of ndarrays for the bars in each experiment.
455 (list): Indices for the locations of the bars for each
456 experiment.
457 """
458 labels_dict = OrderedDict()
459 all_pvalues = []
460 all_inds = []
461
462 if isinstance(data, dict):
463 data = [data]
464 if number_to_keep is not None:
465 data = _unify_labels(_keep_largest_items(execution, number_to_keep) for execution in data)
466
467 for execution in data:
468 values = []
469 for key in labels:
470 if key not in execution:
471 if number_to_keep is None:
472 labels_dict[key] = 1
473 values.append(0)
474 else:
475 labels_dict[key] = 1
476 values.append(execution[key])
477 if kind == "counts":
478 pvalues = np.array(values, dtype=int)
479 else:
480 pvalues = np.array(values, dtype=float)
481 pvalues /= np.sum(pvalues)
482 all_pvalues.append(pvalues)
483 numelem = len(values)
484 ind = np.arange(numelem) # the x locations for the groups
485 all_inds.append(ind)
486
487 return labels_dict, all_pvalues, all_inds

Callers 1

_plotting_coreFunction · 0.85

Calls 5

_unify_labelsFunction · 0.85
_keep_largest_itemsFunction · 0.85
arrayMethod · 0.80
sumMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected