qiskit-documentation/docs/guides/visualize-results.ipynb

316 lines
63 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "2d16e04d-7dee-4e47-b009-bbd50c247fdf",
"metadata": {},
"source": [
"# Visualize results"
]
},
{
"cell_type": "markdown",
"id": "4f548f5a-9fee-498b-b54a-92da5acb2161",
"metadata": {
"tags": [
"version-info"
]
},
"source": [
"<details>\n",
"<summary><b>Package versions</b></summary>\n",
"\n",
"The code on this page was developed using the following requirements.\n",
"We recommend using these versions or newer.\n",
"\n",
"```\n",
"qiskit[all]~=1.2.4\n",
"qiskit-aer~=0.15.1\n",
"qiskit-ibm-runtime~=0.31.0\n",
"qiskit-serverless~=0.17.1\n",
"qiskit-ibm-catalog~=0.1\n",
"```\n",
"</details>"
]
},
{
"cell_type": "markdown",
"id": "7373f30c-a034-4abf-9dd9-71d74c8b296e",
"metadata": {},
"source": [
"## Plot histogram <a name='histogram'></a>\n",
"\n",
"The `plot_histogram` function visualizes the result of sampling a quantum circuit on a QPU or simulator.\n",
"\n",
"<Admonition title=\"Using the output from functions\" type=\"tip\">\n",
"This function returns a `matplotlib.Figure` object. When the last line of a code cell outputs these objects, Jupyter notebooks display them below the cell. If you call these functions in some other environments or in scripts, you will need to explicitly show or save the outputs.\n",
"\n",
"Two options are:\n",
"- Call `.show()` on the returned object to open the image in a new window (assuming your configured matplotlib backend is interactive).\n",
"- Call `.savefig(\"out.png\")` to save the figure to `out.png` in the current working directory. The `savefig()` method takes a path so you can adjust the location and filename where you're saving the output. For example, `plot_state_city(psi).savefig(\"out.png\")`.\n",
"</Admonition>\n",
"\n",
"For example, make a two-qubit Bell state:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "811db4f5-91f4-4781-afae-a42ce75fe12c",
"metadata": {},
"outputs": [],
"source": [
"from qiskit_aer.primitives import Sampler\n",
"\n",
"from qiskit import QuantumCircuit\n",
"from qiskit.visualization import plot_histogram"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "88d4c428-decd-41f7-aaf7-1ebafea37249",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{3: 0.512, 0: 0.488}\n"
]
}
],
"source": [
"# quantum circuit to make a Bell state\n",
"bell = QuantumCircuit(2)\n",
"bell.h(0)\n",
"bell.cx(0, 1)\n",
"bell.measure_all()\n",
"\n",
"# execute the quantum circuit\n",
"quasi_dists = Sampler().run(bell, shots=1000).result().quasi_dists[0]\n",
"print(quasi_dists)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f217705f-f930-411f-be6e-ea06eb5c877b",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg width=\"418.34pt\" height=\"296.8pt\" version=\"1.1\" viewBox=\"0 0 418.34 296.8\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><defs><style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style></defs><path d=\"m0 296.8h418.34v-296.8h-418.34z\" fill=\"#ffffff\"/><path d=\"m54.015 273.31h357.12v-266.11h-357.12z\" fill=\"#ffffff\"/><defs><path id=\"96aa8c3fdf1\" d=\"m0 0v3.5\" stroke=\"#343a3f\" stroke-width=\".8\"/></defs><use x=\"124.356818\" y=\"273.312\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#96aa8c3fdf1\"/><g transform=\"translate(129.32 288.89) rotate(-70) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-30\" transform=\"scale(.015625)\" d=\"m2034 4250q-487 0-733-480-245-479-245-1442 0-959 245-1439 246-480 733-480 491 0 736 480 246 480 246 1439 0 963-246 1442-245 480-736 480zm0 500q785 0 1199-621 414-620 414-1801 0-1178-414-1799-414-620-1199-620-784 0-1198 620-414 621-414 1799 0 1181 414 1801 414 621 1198 621z\"/></defs><use xlink:href=\"#DejaVuSans-30\"/></g><use x=\"340.793182\" y=\"273.312\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#96aa8c3fdf1\"/><g transform=\"translate(345.76 288.89) rotate(-70) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-33\" transform=\"scale(.015625)\" d=\"m2597 2516q453-97 707-404 255-306 255-756 0-690-475-1069-475-378-1350-378-293 0-604 58t-642 174v609q262-153 574-231 313-78 654-78 593 0 904 234t311 681q0 413-289 645-289 233-804 233h-544v519h569q465 0 712 186t247 536q0 359-255 551-254 193-729 193-260 0-557-57-297-56-653-174v562q360 100 674 150t592 50q719 0 1137-327 419-326 419-882 0-388-222-655t-631-370z\"/></defs><use xlink:href=\"#DejaVuSans-33\"/></g><path d=\"m54.015 273.31h357.12\" clip-path=\"url(#a4a3500e55d)\" fill=\"none\" stroke=\"#dde1e6\" stroke-dasharray=\"2.96,1.28\" stroke-width=\".8\"/><defs><path id=\"edf69ef3e15\" d=\"m0 0h-3.5\" stroke=\"#343a3f\" stroke-width=\".8\"/></defs><use x=\"54.015\" y=\"273.312\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#edf69ef3e15\"/><g transform=\"translate(24.749 277.11) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-2e\" transform=\"scale(.015625)\" d=\"m684 794h660v-794h-660v794z\"/></defs><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-30\"/><use x=\"159.033203\" xlink:href=\"#DejaVuSans-30\"/></g><path d=\"m54.015 202.44h357.12\" clip-path=\"url(#a4a3500e55d)\" fill=\"none\" stroke=\"#dde1e6\" stroke-dasharray=\"2.96,1.28\" stroke-width=\".8\"/><use x=\"54.015\" y=\"202.437\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#edf69ef3e15\"/><g transform=\"translate(24.749 206.24) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-31\" transform=\"scale(.015625)\" d=\"m794 531h1031v3560l-1122-225v575l1116 225h631v-4135h1031v-531h-2687v531z\"/><path id=\"DejaVuSans-35\" transform=\"scale(.015625)\" d=\"m691 4666h2478v-532h-1900v-1143q137 47 274 70 138 23 276 23 781 0 1237-428 457-428 457-1159 0-753-469-1171-469-417-1322-417-294 0-599 50-304 50-629 150v635q281-153 581-228t634-75q541 0 856 284 316 284 316 772 0 487-316 771-315 285-856 285-253 0-505-56-251-56-513-175v2344z\"/></defs><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-31\"/><use x=\"159.033203\" xlink:href=\"#DejaVuSans-35\"/></g><path d=\"m54.015 131.56h357.12\" clip-path=\"url(#a4a3500e55d)\" fill=\"none\" stroke=\"#dde1e6\" stroke-dasharray=\"2.96,1.28\" stroke-width=\".8\"/><use x=\"54.015\" y=\"131.562\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#edf69ef3e15\"/><g transform=\"translate(24.749 135.36) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-33\"/><use x=\"159.033203\" xlink:href=\"#DejaVuSans-30\"/></g><path d=\"m54.015 60.687h357.12\" clip-path=\"url(#a4a3500e55d)\" fill=\"none\" stroke=\"#dde1e6\" stroke-dasharray=\"2.96,1.28\" stroke-width=\".8\"/><use x=\"54.015\" y=\"60.687\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#edf69ef3e15\"/><g transform=\"translate(24.749 64.486) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-34\" transform=\"scale(.015625)\" d=\"m2419 4116-1594-2491h1594v2491zm-166 550h794v-3041h666v-525h-666v-1100h-628v1100h-2106v609l1940 2957z\"/></defs><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-34\"/><use x=\"159.033203\" xlink:href=\"#DejaVuSans-35\"/></g><g transform=\"translate(17.838 199.96) rotate(-90) scale(.14 -.14)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-51\" transform=\"scale(.015625)\" d=\"m2522 4238q-688 0-1093-513-404-512-404-1397 0-881 404-1394 405-512 1093-512 687 0 1089 512 402 513 402 1394 0 885-402 1397-402 513-1089 513zm884-4154 832-909h-763l-691 747q-103-6-158-9-54-4-104-4-984 0-1574 658-589 658-589 1761 0 1106 589 1764 590 658 1574 658 981 0 1568-658 588-658 588-1764 0-812-327-1391-326-578-945-853z\"/><path id=\"DejaVuSans-75\" transform=\"scale(.015625)\" d=\"m544 1381v2119h575v-2097q0-497 193-746 194-248 582-248 465 0 735 297 271 297 271 810v1984h575v-3500h-575v538q-209-319-486-474-276-155-642-155-603 0-916 375-312 375-312 1097zm1447 2203z\"/><path id=\"DejaVuSans-61\" transform=\"scale(.015625)\" d=\"m2194 1759q-697 0-966-159t-269-544q0-306 202-486 202-179 548-179 479 0 768 339t289 901v128h-572zm1147 238v-1997h-575v531q-197-318-491-470t-719-152q-537 0-855 302-317 302-317 808 0 590 395 890 396 300 1180 300h807v57q0 397-261 614t-733 217q-300 0-585-72-284-72-546-216v532q315 122 612 182 297 61 578 61 760 0 1135-394 375-393 375-1193z\"/><path id=\"DejaVuSans-73\" transform=\"scale(.015625)\" d=\"m2834 3397v-544q-243 125-506 187-262 63-544 63-428 0-642-131t-214-394q0-200 153-314t616-217l197-44q612-131 870-370t258-667q0-488-386-773-386-284-1061-284-281 0-586 55t-642 164v594q319-166 628-249 309-82 613-82 406 0 624 139 219 139 219 392 0 234-158 359-157 125-692 241l-200 47q-534 112-772 345-237 233-237 639 0 494 350 762 350 269 994 269 318 0 599-47 282-46 519-140z\"/><path id=\"DejaVuSans-69\" transform=\"scale(.015625)\" d=\"m603 3500h575v-3500h-575v3500zm0 1363h575v-729h-575v729z\"/><path id=\"DejaVuSans-2d\" transform=\"scale(.015625)\" d=\"m313 2009h1684v-512h-1684v512z\"/><path id=\"DejaVuSans-70\" transform=\"scale(.015625)\" d=\"m1159 525v-1856h-578v4831h578v-531q182 312 458 463 277 152 661 152 638 0 1036-506 399-506 399-1331t-399-1332q-398-506-1036-506-384 0-661 152-276 152-458 464zm1957 1222q0 634-261 995t-717 361q-457 0-718-361t-261-995 261-995 718-361q456 0 717 361t261 995z\"/><path id=\"DejaVuSans-72\" transform=\"scale(.015625)\" d=\"m2631 2963q-97 56-211 82-114 27-251 27-488 0-749-317t-261-911v-1844h-578v3500h578v-544q182 319 472 473 291 155 707 155 59 0 131-8 72-7 159-23l3-590z\"/><path id=\"DejaVuSans-6f\" transform=\"scale(.015625)\" d=\"m1959 3097q-462 0-731-361t-269-989 267-989q268-361 733-361 460 0 728 362 269 363 269 988 0 622-269 986-268 364-728 364zm0 487q750 0 1178-488 429-487 429-1349 0-859-429-1349-428-489-1178-489-753 0-1180 489-426 490-426 1349 0 862 426 1349 427 488 1180 488z\"/><path id=\"DejaVuSans-62\" transform=\"scale(.015625)\" d=\"m3116 1747q0 634-261 995t-717 361q-457 0-718-361t-261-995 261-995 718-361q456 0 717 361t261 995zm-1957 1222q182 312 458 463 277 152 661 152 638 0 1036-506 399-506 399-1331t-399-1332q-398-506-1036-506-384 0-661 152-276 152-458 464v-525h-578v4863h578v-1894z\"/><path id=\"DejaVuSans-6c\" transform=\"scale(.015625)\" d=\"m603 4863h575v-4863h-575v4863z\"/><path id=\"DejaVuSans-74\" transform=\"scale(.015625)\" d=\"m1172 4494v-994h1184v-447h-1184v-1900q0-428 117-550t477-122h590v-481h-590q-666 0-919 248-253 249-253 905v1900h-422v447h422v994h578z\"/><path id=\"DejaVuSans-79\" transform=\"scale(.015625)\" d=\"m2059-325q-243-625-475-815-231-191-618-191h-460v481h338q237 0 368 113 132 112 291 531l103 262-1415 3444h609l1094-2737 1094 2737h609l-1538-3825z\"/></defs><use xlink:href=\"#DejaVuSans-51\"/><use x=\"78.710938\" xlink:href=\"#DejaVuSans-75\"/><use x=\"142.089844\" xlink:href=\"#DejaVuSans-61\"/><use x=\"203.369141\" xlink:href=\"#DejaVuSans-73\"/><use x=\"255.46875\" xlink:href=\"#DejaVuSans-69\"/><use x=\"283.251953\" xlink:href=\"#DejaVuSans-2d\"/><use x=\"319.335938\" xlink:href=\"#DejaVuSans-70\"/><use x=\"382.8125\" xlink:href=\"#DejaVuSans-72\"/><use x=\"421.675781\" xlink:href=\"#DejaVuSans-6f\"/><use x=\"482.857422\" xlink:href=\"#DejaVuSans-62\"/><use x=\"546.333984\" xlink:href=\"#DejaVuSans-61\"/><use x=\"607.613281\" xlink:href=\"#DejaVuSans-62\"/><use x=\"671.089844\" xlink:href=\"#DejaVuSans-69\"/><use x=\"698.873047\" xlink:href=\"#DejaVuSans-6c\"/><use x=\"726.65625\" xlink:href=\"#DejaVuSans-69\"/><use x=\"754.439453\" xlink:href=\"#DejaVuSans-74\"/><use x=\"793.648438\" xlink:href=\"#DejaVuSans-79\"/></g><path d=\"m70.248 273.31h108.22v-230.58h-108.22z\" clip-path=\"url(#a4a3500e55d)\" fill=\"#1192e8\"/><path d=\"m286.68 273.31h108.22v-241.92h-108.22z\" clip-path=\"url(#a4a3500e55d)\" fill=\"#1192e8\"/><path d=\"m54.015 273.31v-266.11\" fill=\"none\" stroke=\"#343a3f\" stroke-linecap=\"square\" stroke-width=\".8\"/><path d=\"m54.015 273.31h357.12\" fill=\"none\" stroke=\"#343a3f\" stroke-linecap=\"square\" stroke-width=\".8\"/><g transform=\"translate(110.04 29.123) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-38\" transform=\"scale(.015625)\" d=\"m2034 2216q-450 0-708-241-257-241-257-662 0-422 257-663 258-241 708-241t709 242q260 243 260 662 0 421-258 662-257 241-711 241zm-631 268q-406 100-633 378-226 279-226 679 0 559 398 884 399 325 1092 325 697 0 1094-325t397-884q0-400-227-679-226-278-629-378 456-106 710-416 255-309 255-755 0-679-414-1042-414-362-1186-362-771 0-1186 362-414 363-414 1042 0 446 256 755 257 310 713 416zm-231 997q0-362 226-565 227-203 636-203 407 0 636 203 230 203 230 565 0 363-230 566-229 203-636 203-409 0-636-203-226-203-226-566z\"/></defs><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-34\"/><use x=\"159.033203\" xlink:href=\"#DejaVuSans-38\"/><use x=\"222.65625\" xlink:href=\"#DejaVuSans-38\"/></g><g transform=\"translate(326.48 17.216) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-32\" transform=\"scale(.015625)\" d=\"m1228 531h2203v-531h-2962v531q359 372 979 998 621 627 780 809 303 340 423 576 121 236 121 464 0 372-261 606-261 235-680 235-297 0-627-103-329-103-704-313v638q381 153 712 231 332 78 607 78 725 0 1156-363 431-362 431-968 0-288-108-546-107-257-392-607-78-91-497-524-418-433-1181-1211z\"/></defs><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-35\"/><use x=\"159.033203\" xlink:href=\"#DejaVuSans-31\"/><use x=\"222.65625\" xlink:href=\"#DejaVuSans-32\"/></g><defs><clipPath id=\"a4a3500e55d\"><rect x=\"54.015\" y=\"7.2\" width=\"357.12\" height=\"266.11\"/></clipPath></defs></svg>"
],
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot_histogram(quasi_dists)"
]
},
{
"cell_type": "markdown",
"id": "57a1f479-3a5c-4eb4-a550-48c12d8f5c17",
"metadata": {},
"source": [
"### Options when plotting a histogram\n",
"\n",
"Use the following options for `plot_histogram` to adjust the output graph.\n",
"\n",
"* `legend`: Provides a label for the executions. It takes a list of strings used to label each execution's results. This is mostly useful when plotting multiple execution results in the same histogram\n",
"* `sort`: Adjusts the order of the bars in the histogram. It can be set to either ascending order with `asc` or descending order with `desc`\n",
"* `number_to_keep`: Takes an integer for the number of terms to show. The rest are grouped together in a single bar called \"rest\"\n",
"* `color`: Adjusts the color of the bars; takes a string or a list of strings for the colors to use for the bars for each execution\n",
"* `bar_labels`: Adjusts whether labels are printed above the bars\n",
"* `figsize`: Takes a tuple of the size in inches to make the output figure"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "2c67a5f1-20c0-4d95-bfb5-37509862880f",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg width=\"978.25pt\" height=\"695.97pt\" version=\"1.1\" viewBox=\"0 0 978.25 695.97\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><defs><style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style></defs><path d=\"m0 695.97h978.25v-695.97h-978.25z\" fill=\"#ffffff\"/><path d=\"m54.015 672.48h837v-665.28h-837z\" fill=\"#ffffff\"/><defs><path id=\"d76d81d091a\" d=\"m0 0v3.5\" stroke=\"#343a3f\" stroke-width=\".8\"/></defs><use x=\"700.787727\" y=\"672.48\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#d76d81d091a\"/><g transform=\"translate(705.75 688.06) rotate(-70) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-30\" transform=\"scale(.015625)\" d=\"m2034 4250q-487 0-733-480-245-479-245-1442 0-959 245-1439 246-480 733-480 491 0 736 480 246 480 246 1439 0 963-246 1442-245 480-736 480zm0 500q785 0 1199-621 414-620 414-1801 0-1178-414-1799-414-620-1199-620-784 0-1198 620-414 621-414 1799 0 1181 414 1801 414 621 1198 621z\"/></defs><use xlink:href=\"#DejaVuSans-30\"/></g><use x=\"244.242273\" y=\"672.48\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#d76d81d091a\"/><g transform=\"translate(249.21 688.06) rotate(-70) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-33\" transform=\"scale(.015625)\" d=\"m2597 2516q453-97 707-404 255-306 255-756 0-690-475-1069-475-378-1350-378-293 0-604 58t-642 174v609q262-153 574-231 313-78 654-78 593 0 904 234t311 681q0 413-289 645-289 233-804 233h-544v519h569q465 0 712 186t247 536q0 359-255 551-254 193-729 193-260 0-557-57-297-56-653-174v562q360 100 674 150t592 50q719 0 1137-327 419-326 419-882 0-388-222-655t-631-370z\"/></defs><use xlink:href=\"#DejaVuSans-33\"/></g><path d=\"m54.015 672.48h837\" clip-path=\"url(#f16dd27faad)\" fill=\"none\" stroke=\"#dde1e6\" stroke-dasharray=\"2.96,1.28\" stroke-width=\".8\"/><defs><path id=\"870fe60cce4\" d=\"m0 0h-3.5\" stroke=\"#343a3f\" stroke-width=\".8\"/></defs><use x=\"54.015\" y=\"672.48\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#870fe60cce4\"/><g transform=\"translate(24.749 676.28) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-2e\" transform=\"scale(.015625)\" d=\"m684 794h660v-794h-660v794z\"/></defs><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-30\"/><use x=\"159.033203\" xlink:href=\"#DejaVuSans-30\"/></g><path d=\"m54.015 495.64h837\" clip-path=\"url(#f16dd27faad)\" fill=\"none\" stroke=\"#dde1e6\" stroke-dasharray=\"2.96,1.28\" stroke-width=\".8\"/><use x=\"54.015\" y=\"495.637895\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#870fe60cce4\"/><g transform=\"translate(24.749 499.44) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-31\" transform=\"scale(.015625)\" d=\"m794 531h1031v3560l-1122-225v575l1116 225h631v-4135h1031v-531h-2687v531z\"/><path id=\"DejaVuSans-35\" transform=\"scale(.015625)\" d=\"m691 4666h2478v-532h-1900v-1143q137 47 274 70 138 23 276 23 781 0 1237-428 457-428 457-1159 0-753-469-1171-469-417-1322-417-294 0-599 50-304 50-629 150v635q281-153 581-228t634-75q541 0 856 284 316 284 316 772 0 487-316 771-315 285-856 285-253 0-505-56-251-56-513-175v2344z\"/></defs><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-31\"/><use x=\"159.033203\" xlink:href=\"#DejaVuSans-35\"/></g><path d=\"m54.015 318.8h837\" clip-path=\"url(#f16dd27faad)\" fill=\"none\" stroke=\"#dde1e6\" stroke-dasharray=\"2.96,1.28\" stroke-width=\".8\"/><use x=\"54.015\" y=\"318.795789\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#870fe60cce4\"/><g transform=\"translate(24.749 322.6) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-33\"/><use x=\"159.033203\" xlink:href=\"#DejaVuSans-30\"/></g><path d=\"m54.015 141.95h837\" clip-path=\"url(#f16dd27faad)\" fill=\"none\" stroke=\"#dde1e6\" stroke-dasharray=\"2.96,1.28\" stroke-width=\".8\"/><use x=\"54.015\" y=\"141.953684\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#870fe60cce4\"/><g transform=\"translate(24.749 145.75) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-34\" transform=\"scale(.015625)\" d=\"m2419 4116-1594-2491h1594v2491zm-166 550h794v-3041h666v-525h-666v-1100h-628v1100h-2106v609l1940 2957z\"/></defs><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-34\"/><use x=\"159.033203\" xlink:href=\"#DejaVuSans-35\"/></g><g transform=\"translate(17.838 399.54) rotate(-90) scale(.14 -.14)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-51\" transform=\"scale(.015625)\" d=\"m2522 4238q-688 0-1093-513-404-512-404-1397 0-881 404-1394 405-512 1093-512 687 0 1089 512 402 513 402 1394 0 885-402 1397-402 513-1089 513zm884-4154 832-909h-763l-691 747q-103-6-158-9-54-4-104-4-984 0-1574 658-589 658-589 1761 0 1106 589 1764 590 658 1574 658 981 0 1568-658 588-658 588-1764 0-812-327-1391-326-578-945-853z\"/><path id=\"DejaVuSans-75\" transform=\"scale(.015625)\" d=\"m544 1381v2119h575v-2097q0-497 193-746 194-248 582-248 465 0 735 297 271 297 271 810v1984h575v-3500h-575v538q-209-319-486-474-276-155-642-155-603 0-916 375-312 375-312 1097zm1447 2203z\"/><path id=\"DejaVuSans-61\" transform=\"scale(.015625)\" d=\"m2194 1759q-697 0-966-159t-269-544q0-306 202-486 202-179 548-179 479 0 768 339t289 901v128h-572zm1147 238v-1997h-575v531q-197-318-491-470t-719-152q-537 0-855 302-317 302-317 808 0 590 395 890 396 300 1180 300h807v57q0 397-261 614t-733 217q-300 0-585-72-284-72-546-216v532q315 122 612 182 297 61 578 61 760 0 1135-394 375-393 375-1193z\"/><path id=\"DejaVuSans-73\" transform=\"scale(.015625)\" d=\"m2834 3397v-544q-243 125-506 187-262 63-544 63-428 0-642-131t-214-394q0-200 153-314t616-217l197-44q612-131 870-370t258-667q0-488-386-773-386-284-1061-284-281 0-586 55t-642 164v594q319-166 628-249 309-82 613-82 406 0 624 139 219 139 219 392 0 234-158 359-157 125-692 241l-200 47q-534 112-772 345-237 233-237 639 0 494 350 762 350 269 994 269 318 0 599-47 282-46 519-140z\"/><path id=\"DejaVuSans-69\" transform=\"scale(.015625)\" d=\"m603 3500h575v-3500h-575v3500zm0 1363h575v-729h-575v729z\"/><path id=\"DejaVuSans-2d\" transform=\"scale(.015625)\" d=\"m313 2009h1684v-512h-1684v512z\"/><path id=\"DejaVuSans-70\" transform=\"scale(.015625)\" d=\"m1159 525v-1856h-578v4831h578v-531q182 312 458 463 277 152 661 152 638 0 1036-506 399-506 399-1331t-399-1332q-398-506-1036-506-384 0-661 152-276 152-458 464zm1957 1222q0 634-261 995t-717 361q-457 0-718-361t-261-995 261-995 718-361q456 0 717 361t261 995z\"/><path id=\"DejaVuSans-72\" transform=\"scale(.015625)\" d=\"m2631 2963q-97 56-211 82-114 27-251 27-488 0-749-317t-261-911v-1844h-578v3500h578v-544q182 319 472 473 291 155 707 155 59 0 131-8 72-7 159-23l3-590z\"/><path id=\"DejaVuSans-6f\" transform=\"scale(.015625)\" d=\"m1959 3097q-462 0-731-361t-269-989 267-989q268-361 733-361 460 0 728 362 269 363 269 988 0 622-269 986-268 364-728 364zm0 487q750 0 1178-488 429-487 429-1349 0-859-429-1349-428-489-1178-489-753 0-1180 489-426 490-426 1349 0 862 426 1349 427 488 1180 488z\"/><path id=\"DejaVuSans-62\" transform=\"scale(.015625)\" d=\"m3116 1747q0 634-261 995t-717 361q-457 0-718-361t-261-995 261-995 718-361q456 0 717 361t261 995zm-1957 1222q182 312 458 463 277 152 661 152 638 0 1036-506 399-506 399-1331t-399-1332q-398-506-1036-506-384 0-661 152-276 152-458 464v-525h-578v4863h578v-1894z\"/><path id=\"DejaVuSans-6c\" transform=\"scale(.015625)\" d=\"m603 4863h575v-4863h-575v4863z\"/><path id=\"DejaVuSans-74\" transform=\"scale(.015625)\" d=\"m1172 4494v-994h1184v-447h-1184v-1900q0-428 117-550t477-122h590v-481h-590q-666 0-919 248-253 249-253 905v1900h-422v447h422v994h578z\"/><path id=\"DejaVuSans-79\" transform=\"scale(.015625)\" d=\"m2059-325q-243-625-475-815-231-191-618-191h-460v481h338q237 0 368 113 132 112 291 531l103 262-1415 3444h609l1094-2737 1094 2737h609l-1538-3825z\"/></defs><use xlink:href=\"#DejaVuSans-51\"/><use x=\"78.710938\" xlink:href=\"#DejaVuSans-75\"/><use x=\"142.089844\" xlink:href=\"#DejaVuSans-61\"/><use x=\"203.369141\" xlink:href=\"#DejaVuSans-73\"/><use x=\"255.46875\" xlink:href=\"#DejaVuSans-69\"/><use x=\"283.251953\" xlink:href=\"#DejaVuSans-2d\"/><use x=\"319.335938\" xlink:href=\"#DejaVuSans-70\"/><use x=\"382.8125\" xlink:href=\"#DejaVuSans-72\"/><use x=\"421.675781\" xlink:href=\"#DejaVuSans-6f\"/><use x=\"482.857422\" xlink:href=\"#DejaVuSans-62\"/><use x=\"546.333984\" xlink:href=\"#DejaVuSans-61\"/><use x=\"607.613281\" xlink:href=\"#DejaVuSans-62\"/><use x=\"671.089844\" xlink:href=\"#DejaVuSans-69\"/><use x=\"698.873047\" xlink:href=\"#DejaVuSans-6c\"/><use x=\"726.65625\" xlink:href=\"#DejaVuSans-69\"/><use x=\"754.439453\" xlink:href=\"#DejaVuSans-74\"/><use x=\"793.648438\" xlink:href=\"#DejaVuSans-79\"/></g><path d=\"m852.97 672.48h-152.18v-575.33h152.18z\" clip-path=\"url(#f16dd27faad)\" fill=\"#ffa500\"/><path d=\"m396.42 672.48h-152.18v-603.62h152.18z\" clip-path=\"url(#f16dd27faad)\" fill=\"#ffa500\"/><path d=\"m700.79 672.48h-152.18v-574.15h152.18z\" clip-path=\"url(#f16dd27faad)\"/><path d=\"m244.24 672.48h-152.18v-604.8h152.18z\" clip-path=\"url(#f16dd27faad)\"/><path d=\"m54.015 672.48v-665.28\" fill=\"none\" stroke=\"#343a3f\" stroke-linecap=\"square\" stroke-width=\".8\"/><path d=\"m54.015 672.48h837\" fill=\"none\" stroke=\"#343a3f\" stroke-linecap=\"square\" stroke-width=\".8\"/><path d=\"m899.38 39.556h71.666v-32.356h-71.666z\" fill=\"#ffffff\" opacity=\".8\" stroke=\"#cccccc\"/><path d=\"m903.38 18.798h20v-7h-20z\" fill=\"#ffa500\"/><g transform=\"translate(931.38 18.798) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-66\" transform=\"scale(.015625)\" d=\"m2375 4863v-479h-550q-309 0-430-125-120-125-120-450v-309h947v-447h-947v-3053h-578v3053h-550v447h550v244q0 584 272 851 272 268 862 268h544z\"/></defs><use xlink:href=\"#DejaVuSans-66\"/><use x=\"35.205078\" xlink:href=\"#DejaVuSans-69\"/><use x=\"62.988281\" xlink:href=\"#DejaVuSans-72\"/><use x=\"104.101562\" xlink:href=\"#DejaVuSans-73\"/><use x=\"156.201172\" xlink:href=\"#DejaVuSans-74\"/></g><path d=\"m903.38 33.477h20v-7h-20z\"/><g transform=\"translate(931.38 33.477) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-65\" transform=\"scale(.015625)\" d=\"m3597 1894v-281h-2644q38-594 358-905t892-311q331 0 642 81t618 244v-544q-310-131-635-200t-659-69q-838 0-1327 487-489 488-489 1320 0 859 464 1363 464 505 1252 505 706 0 1117-455 411-454 411-1235zm-575 169q-6 471-264 752-258 282-683 282-481 0-770-272t-333-766l2050 4z\"/><path id=\"DejaVuSans-63\" transform=\"scale(.015625)\" d=\"m3122 3366v-538q-244 135-489 202t-495 67q-560 0-870-355-309-354-309-995t309-996q310-354 870-354 250 0 495 67t489 202v-532q-241-112-499-168-257-57-548-57-791 0-1257 497-465 497-465 1341 0 856 470 1346 471 491 1290 491 265 0 518-55 253-54 491-163z\"/><path id=\"DejaVuSans-6e\" transform=\"scale(.015625)\" d=\"m3513 2113v-2113h-575v2094q0 497-194 743-194 247-581 247-466 0-735-297-269-296-269-809v-1978h-578v3500h578v-544q207 316 486 472 280 156 646 156 603 0 912-373 310-373 310-1098z\"/><path id=\"DejaVuSans-64\" transform=\"scale(.015625)\" d=\"m2906 2969v1894h575v-4863h-575v525q-181-312-458-464-276-152-664-152-634 0-1033 506-398 507-398 1332t398 1331q399 506 1033 506 388 0 664-152 277-151 458-463zm-1959-1222q0-634 261-995t717-361 718 361q263 361 263 995t-263 995q-262 361-718 361t-717-361-261-995z\"/></defs><use xlink:href=\"#DejaVuSans-73\"/><use x=\"52.099609\" xlink:href=\"#DejaVuSans-65\"/><use x=\"113.623047\" xlink:href=\"#DejaVuSans-63\"/><use x=\"168.603516\" xlink:href=\"#DejaVuSans-6f\"/><use x=\"229.785156\" xlink:href=\"#DejaVuSans-6e\"/><use x=\"293.164062\" xlink:href=\"#DejaVuSans-64\"/></g><defs><clipPath id=\"f16dd27faad\"><rect x=\"54.015\" y=\"7.2\" width=\"837\" height=\"665.28\"/></clipPath></defs></svg>"
],
"text/plain": [
"<Figure size 1500x1200 with 1 Axes>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Execute two-qubit Bell state again\n",
"second_quasi_dists = Sampler().run(bell, shots=1000).result().quasi_dists[0]\n",
"\n",
"# Plot results with custom options\n",
"plot_histogram(\n",
" [quasi_dists, second_quasi_dists],\n",
" legend=[\"first\", \"second\"],\n",
" sort=\"desc\",\n",
" figsize=(15, 12),\n",
" color=[\"orange\", \"black\"],\n",
" bar_labels=False,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "b103e76b-5df8-41e3-b8ad-4d62eb0bc378",
"metadata": {},
"source": [
"## Plotting estimator results\n",
"\n",
"Qiskit does not have a built-in function for plotting Estimator results, but you can use Matplotlib's [`bar` plot](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar.html) for a quick visualization.\n",
"\n",
"To demonstrate, the following cell estimates the expectation values of seven different observables on a quantum state."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "d97cd321-7acf-45a7-bfc3-823e225154c7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"EstimatorResult(values=array([ 0.43554688, 0.03125 , 0.45117188, -0.015625 , -0.65039062,\n",
" 0.03710938, 0.74023438]), metadata=[{'shots': 1024, 'variance': 0.8102989196777344, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.010349305, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.02155229, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}, {'shots': 1024, 'variance': 0.9990234375, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.020299714, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.03565741, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}, {'shots': 1024, 'variance': 0.7964439392089844, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.016613657, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.037284611, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}, {'shots': 1024, 'variance': 0.999755859375, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.020662932, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.041528602, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}, {'shots': 1024, 'variance': 0.5769920349121094, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.021179425, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.038660703, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}, {'shots': 1024, 'variance': 0.9986228942871094, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.015370644, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.028125562, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}, {'shots': 1024, 'variance': 0.4520530700683594, 'simulator_metadata': [{'num_bind_params': 1, 'runtime_parameter_bind': False, 'parallel_state_update': 16, 'parallel_shots': 1, 'sample_measure_time': 0.020390522, 'noise': 'ideal', 'batched_shots_optimization': False, 'remapped_qubits': False, 'active_input_qubits': [0, 1], 'device': 'CPU', 'time_taken': 0.040900633, 'measure_sampling': True, 'num_clbits': 2, 'max_memory_mb': 32768, 'input_qubit_map': [[1, 1], [0, 0]], 'num_qubits': 2, 'method': 'statevector', 'required_memory_mb': 1, 'fusion': {'enabled': True, 'threshold': 14, 'applied': False, 'max_fused_qubits': 5}}]}])\n"
]
},
{
"data": {
"text/plain": [
"<BarContainer object of 7 artists>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg width=\"402.8pt\" height=\"299.29pt\" version=\"1.1\" viewBox=\"0 0 402.8 299.29\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><defs><style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style></defs><path d=\"m0 299.29h402.8v-299.29h-402.8z\" fill=\"#ffffff\"/><path d=\"m38.483 275.41h357.12v-266.11h-357.12z\" fill=\"#ffffff\"/><path d=\"m54.716 150.17h38.195v-75.77h-38.195z\" clip-path=\"url(#a1aabba4d3f)\" fill=\"#1192e8\"/><path d=\"m102.46 150.17h38.195v-5.4364h-38.195z\" clip-path=\"url(#a1aabba4d3f)\" fill=\"#1192e8\"/><path d=\"m150.2 150.17h38.195v-78.488h-38.195z\" clip-path=\"url(#a1aabba4d3f)\" fill=\"#1192e8\"/><path d=\"m197.95 150.17h38.195v2.7182h-38.195z\" clip-path=\"url(#a1aabba4d3f)\" fill=\"#1192e8\"/><path d=\"m245.69 150.17h38.195v113.15h-38.195z\" clip-path=\"url(#a1aabba4d3f)\" fill=\"#1192e8\"/><path d=\"m293.43 150.17h38.195v-6.4557h-38.195z\" clip-path=\"url(#a1aabba4d3f)\" fill=\"#1192e8\"/><path d=\"m341.18 150.17h38.195v-128.77h-38.195z\" clip-path=\"url(#a1aabba4d3f)\" fill=\"#1192e8\"/><defs><path id=\"26ae64cef7a\" d=\"m0 0v3.5\" stroke=\"#343a3f\" stroke-width=\".8\"/></defs><use x=\"73.812866\" y=\"275.412342\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#26ae64cef7a\"/><g transform=\"translate(66.963 290.01) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-5a\" transform=\"scale(.015625)\" d=\"m359 4666h3666v-482l-2950-3653h3022v-531h-3809v481l2950 3653h-2879v532z\"/></defs><use xlink:href=\"#DejaVuSans-5a\"/><use x=\"68.505859\" xlink:href=\"#DejaVuSans-5a\"/></g><use x=\"121.556181\" y=\"275.412342\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#26ae64cef7a\"/><g transform=\"translate(114.71 290.01) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-58\" transform=\"scale(.015625)\" d=\"m403 4666h678l1160-1735 1165 1735h678l-1500-2241 1600-2425h-678l-1312 1984-1322-1984h-681l1665 2491-1453 2175z\"/></defs><use xlink:href=\"#DejaVuSans-58\"/><use x=\"68.505859\" xlink:href=\"#DejaVuSans-58\"/></g><use x=\"169.299497\" y=\"275.412342\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#26ae64cef7a\"/><g transform=\"translate(162.82 290.01) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-59\" transform=\"scale(.015625)\" d=\"m-13 4666h679l1293-1919 1285 1919h678l-1650-2444v-2222h-634v2222l-1651 2444z\"/></defs><use xlink:href=\"#DejaVuSans-59\"/><use x=\"61.083984\" xlink:href=\"#DejaVuSans-5a\"/></g><use x=\"217.042813\" y=\"275.412342\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#26ae64cef7a\"/><g transform=\"translate(210.56 290.01) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-5a\"/><use x=\"68.505859\" xlink:href=\"#DejaVuSans-59\"/></g><use x=\"264.786128\" y=\"275.412342\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#26ae64cef7a\"/><g transform=\"translate(258.31 290.01) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-58\"/><use x=\"68.505859\" xlink:href=\"#DejaVuSans-59\"/></g><use x=\"312.529444\" y=\"275.412342\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#26ae64cef7a\"/><g transform=\"translate(305.68 290.01) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-58\"/><use x=\"68.505859\" xlink:href=\"#DejaVuSans-5a\"/></g><use x=\"360.272759\" y=\"275.412342\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#26ae64cef7a\"/><g transform=\"translate(353.42 290.01) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-5a\"/><use x=\"68.505859\" xlink:href=\"#DejaVuSans-58\"/></g><defs><path id=\"935638ca77c\" d=\"m0 0h-3.5\" stroke=\"#343a3f\" stroke-width=\".8\"/></defs><use x=\"38.482813\" y=\"254.55014\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#935638ca77c\"/><g transform=\"translate(7.2 258.35) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-2212\" transform=\"scale(.015625)\" d=\"m678 2272h4006v-531h-4006v531z\"/><path id=\"DejaVuSans-30\" transform=\"scale(.015625)\" d=\"m2034 4250q-487 0-733-480-245-479-245-1442 0-959 245-1439 246-480 733-480 491 0 736 480 246 480 246 1439 0 963-246 1442-245 480-736 480zm0 500q785 0 1199-621 414-620 414-1801 0-1178-414-1799-414-620-1199-620-784 0-1198 620-414 621-414 1799 0 1181 414 1801 414 621 1198 621z\"/><path id=\"DejaVuSans-2e\" transform=\"scale(.015625)\" d=\"m684 794h660v-794h-660v794z\"/><path id=\"DejaVuSans-36\" transform=\"scale(.015625)\" d=\"m2113 2584q-425 0-674-291-248-290-248-796 0-503 248-796 249-292 674-292t673 292q248 293 248 796 0 506-248 796-248 291-673 291zm1253 1979v-575q-238 112-480 171-242 60-480 60-625 0-955-422-329-422-376-1275 184 272 462 417 279 145 613 145 703 0 1111-427 408-426 408-1160 0-719-425-1154-425-434-1131-434-810 0-1238 620-428 621-428 1799 0 1106 525 1764t1409 658q238 0 480-47t505-140z\"/></defs><use xlink:href=\"#DejaVuSans-2212\"/><use x=\"83.789062\" xlink:href=\"#DejaVuSans-30\"/><use x=\"147.412109\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"179.199219\" xlink:href=\"#DejaVuSans-36\"/></g><use x=\"38.482813\" y=\"219.757151\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#935638ca77c\"/><g transform=\"translate(7.2 223.56) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-34\" transform=\"scale(.015625)\" d=\"m2419 4116-1594-2491h1594v2491zm-166 550h794v-3041h666v-525h-666v-1100h-628v1100h-2106v609l1940 2957z\"/></defs><use xlink:href=\"#DejaVuSans-2212\"/><use x=\"83.789062\" xlink:href=\"#DejaVuSans-30\"/><use x=\"147.412109\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"179.199219\" xlink:href=\"#DejaVuSans-34\"/></g><use x=\"38.482813\" y=\"184.964163\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#935638ca77c\"/><g transform=\"translate(7.2 188.76) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-32\" transform=\"scale(.015625)\" d=\"m1228 531h2203v-531h-2962v531q359 372 979 998 621 627 780 809 303 340 423 576 121 236 121 464 0 372-261 606-261 235-680 235-297 0-627-103-329-103-704-313v638q381 153 712 231 332 78 607 78 725 0 1156-363 431-362 431-968 0-288-108-546-107-257-392-607-78-91-497-524-418-433-1181-1211z\"/></defs><use xlink:href=\"#DejaVuSans-2212\"/><use x=\"83.789062\" xlink:href=\"#DejaVuSans-30\"/><use x=\"147.412109\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"179.199219\" xlink:href=\"#DejaVuSans-32\"/></g><use x=\"38.482813\" y=\"150.171174\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#935638ca77c\"/><g transform=\"translate(15.58 153.97) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-30\"/></g><use x=\"38.482813\" y=\"115.378185\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#935638ca77c\"/><g transform=\"translate(15.58 119.18) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-32\"/></g><use x=\"38.482813\" y=\"80.585196\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#935638ca77c\"/><g transform=\"translate(15.58 84.384) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-34\"/></g><use x=\"38.482813\" y=\"45.792208\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#935638ca77c\"/><g transform=\"translate(15.58 49.591) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-36\"/></g><use x=\"38.482813\" y=\"10.999219\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#935638ca77c\"/><g transform=\"translate(15.58 14.798) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-38\" transform=\"scale(.015625)\" d=\"m2034 2216q-450 0-708-241-257-241-257-662 0-422 257-663 258-241 708-241t709 242q260 243 260 662 0 421-258 662-257 241-711 241zm-631 268q-406 100-633 378-226 279-226 679 0 559 398 884 399 325 1092 325 697 0 1094-325t397-884q0-400-227-679-226-278-629-378 456-106 710-416 255-309 255-755 0-679-414-1042-414-362-1186-362-771 0-1186 362-414 363-414 1042 0 446 256 755 257 310 713 416zm-231 997q0-362 226-565 227-203 636-203 407 0 636 203 230 203 230 565 0 363-230 566-229 203-636 203-409 0-636-203-226-203-226-566z\"/></defs><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-38\"/></g><path d=\"m38.483 275.41v-266.11\" fill=\"none\" stroke=\"#343a3f\" stroke-linecap=\"square\" stroke-width=\".8\"/><path d=\"m38.483 275.41h357.12\" fill=\"none\" stroke=\"#343a3f\" stroke-linecap=\"square\" stroke-width=\".8\"/><defs><clipPath id=\"a1aabba4d3f\"><rect x=\"38.483\" y=\"9.3003\" width=\"357.12\" height=\"266.11\"/></clipPath></defs></svg>"
],
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from qiskit import QuantumCircuit\n",
"from qiskit.quantum_info import SparsePauliOp\n",
"from qiskit_aer.primitives import Estimator\n",
"from matplotlib import pyplot as plt\n",
"\n",
"# Simple estimation experiment to create results\n",
"qc = QuantumCircuit(2)\n",
"qc.h(0)\n",
"qc.crx(1.5, 0, 1)\n",
"\n",
"observables_labels = [\"ZZ\", \"XX\", \"YZ\", \"ZY\", \"XY\", \"XZ\", \"ZX\"]\n",
"observables = [SparsePauliOp(label) for label in observables_labels]\n",
"\n",
"result = Estimator().run([qc] * 7, observables).result()\n",
"print(result)\n",
"\n",
"# Plot using Matplotlib\n",
"plt.bar(observables_labels, result.values)"
]
},
{
"cell_type": "markdown",
"id": "8f415ec3-19a3-4841-8f32-cd0ec8385f7d",
"metadata": {},
"source": [
"The following cell estimates the [standard error](https://en.wikipedia.org/wiki/Standard_error) from the [variance](https://en.wikipedia.org/wiki/Variance) of each result and adds them as error bars. See the [`bar` plot documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar.html) for a full description of the plot."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4b4b532c-bf79-42bf-bc6a-3877e132c89a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Text(0.5, 1.0, 'Expectation values (with standard errors)')"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg width=\"402.8pt\" height=\"312.31pt\" version=\"1.1\" viewBox=\"0 0 402.8 312.31\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><defs><style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style></defs><path d=\"m0 312.31h402.8v-312.31h-402.8z\" fill=\"#ffffff\"/><path d=\"m38.483 288.43h357.12v-266.11h-357.12z\" fill=\"#ffffff\"/><path d=\"m54.716 162.72h38.195v-73.408h-38.195z\" clip-path=\"url(#9e1b1e44df5)\" fill=\"#1192e8\"/><path d=\"m102.46 162.72h38.195v-5.2669h-38.195z\" clip-path=\"url(#9e1b1e44df5)\" fill=\"#1192e8\"/><path d=\"m150.2 162.72h38.195v-76.041h-38.195z\" clip-path=\"url(#9e1b1e44df5)\" fill=\"#1192e8\"/><path d=\"m197.95 162.72h38.195v2.6335h-38.195z\" clip-path=\"url(#9e1b1e44df5)\" fill=\"#1192e8\"/><path d=\"m245.69 162.72h38.195v109.62h-38.195z\" clip-path=\"url(#9e1b1e44df5)\" fill=\"#1192e8\"/><path d=\"m293.43 162.72h38.195v-6.2545h-38.195z\" clip-path=\"url(#9e1b1e44df5)\" fill=\"#1192e8\"/><path d=\"m341.18 162.72h38.195v-124.76h-38.195z\" clip-path=\"url(#9e1b1e44df5)\" fill=\"#1192e8\"/><defs><path id=\"47518fa15b1\" d=\"m0 0v3.5\" stroke=\"#343a3f\" stroke-width=\".8\"/></defs><use x=\"73.812866\" y=\"288.430125\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#47518fa15b1\"/><g transform=\"translate(66.963 303.03) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-5a\" transform=\"scale(.015625)\" d=\"m359 4666h3666v-482l-2950-3653h3022v-531h-3809v481l2950 3653h-2879v532z\"/></defs><use xlink:href=\"#DejaVuSans-5a\"/><use x=\"68.505859\" xlink:href=\"#DejaVuSans-5a\"/></g><use x=\"121.556181\" y=\"288.430125\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#47518fa15b1\"/><g transform=\"translate(114.71 303.03) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-58\" transform=\"scale(.015625)\" d=\"m403 4666h678l1160-1735 1165 1735h678l-1500-2241 1600-2425h-678l-1312 1984-1322-1984h-681l1665 2491-1453 2175z\"/></defs><use xlink:href=\"#DejaVuSans-58\"/><use x=\"68.505859\" xlink:href=\"#DejaVuSans-58\"/></g><use x=\"169.299497\" y=\"288.430125\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#47518fa15b1\"/><g transform=\"translate(162.82 303.03) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-59\" transform=\"scale(.015625)\" d=\"m-13 4666h679l1293-1919 1285 1919h678l-1650-2444v-2222h-634v2222l-1651 2444z\"/></defs><use xlink:href=\"#DejaVuSans-59\"/><use x=\"61.083984\" xlink:href=\"#DejaVuSans-5a\"/></g><use x=\"217.042813\" y=\"288.430125\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#47518fa15b1\"/><g transform=\"translate(210.56 303.03) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-5a\"/><use x=\"68.505859\" xlink:href=\"#DejaVuSans-59\"/></g><use x=\"264.786128\" y=\"288.430125\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#47518fa15b1\"/><g transform=\"translate(258.31 303.03) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-58\"/><use x=\"68.505859\" xlink:href=\"#DejaVuSans-59\"/></g><use x=\"312.529444\" y=\"288.430125\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#47518fa15b1\"/><g transform=\"translate(305.68 303.03) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-58\"/><use x=\"68.505859\" xlink:href=\"#DejaVuSans-5a\"/></g><use x=\"360.272759\" y=\"288.430125\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#47518fa15b1\"/><g transform=\"translate(353.42 303.03) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-5a\"/><use x=\"68.505859\" xlink:href=\"#DejaVuSans-58\"/></g><defs><path id=\"79e565cabd1\" d=\"m0 0h-3.5\" stroke=\"#343a3f\" stroke-width=\".8\"/></defs><use x=\"38.482813\" y=\"263.840459\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#79e565cabd1\"/><g transform=\"translate(7.2 267.64) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-2212\" transform=\"scale(.015625)\" d=\"m678 2272h4006v-531h-4006v531z\"/><path id=\"DejaVuSans-30\" transform=\"scale(.015625)\" d=\"m2034 4250q-487 0-733-480-245-479-245-1442 0-959 245-1439 246-480 733-480 491 0 736 480 246 480 246 1439 0 963-246 1442-245 480-736 480zm0 500q785 0 1199-621 414-620 414-1801 0-1178-414-1799-414-620-1199-620-784 0-1198 620-414 621-414 1799 0 1181 414 1801 414 621 1198 621z\"/><path id=\"DejaVuSans-2e\" transform=\"scale(.015625)\" d=\"m684 794h660v-794h-660v794z\"/><path id=\"DejaVuSans-36\" transform=\"scale(.015625)\" d=\"m2113 2584q-425 0-674-291-248-290-248-796 0-503 248-796 249-292 674-292t673 292q248 293 248 796 0 506-248 796-248 291-673 291zm1253 1979v-575q-238 112-480 171-242 60-480 60-625 0-955-422-329-422-376-1275 184 272 462 417 279 145 613 145 703 0 1111-427 408-426 408-1160 0-719-425-1154-425-434-1131-434-810 0-1238 620-428 621-428 1799 0 1106 525 1764t1409 658q238 0 480-47t505-140z\"/></defs><use xlink:href=\"#DejaVuSans-2212\"/><use x=\"83.789062\" xlink:href=\"#DejaVuSans-30\"/><use x=\"147.412109\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"179.199219\" xlink:href=\"#DejaVuSans-36\"/></g><use x=\"38.482813\" y=\"230.132157\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#79e565cabd1\"/><g transform=\"translate(7.2 233.93) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-34\" transform=\"scale(.015625)\" d=\"m2419 4116-1594-2491h1594v2491zm-166 550h794v-3041h666v-525h-666v-1100h-628v1100h-2106v609l1940 2957z\"/></defs><use xlink:href=\"#DejaVuSans-2212\"/><use x=\"83.789062\" xlink:href=\"#DejaVuSans-30\"/><use x=\"147.412109\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"179.199219\" xlink:href=\"#DejaVuSans-34\"/></g><use x=\"38.482813\" y=\"196.423855\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#79e565cabd1\"/><g transform=\"translate(7.2 200.22) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-32\" transform=\"scale(.015625)\" d=\"m1228 531h2203v-531h-2962v531q359 372 979 998 621 627 780 809 303 340 423 576 121 236 121 464 0 372-261 606-261 235-680 235-297 0-627-103-329-103-704-313v638q381 153 712 231 332 78 607 78 725 0 1156-363 431-362 431-968 0-288-108-546-107-257-392-607-78-91-497-524-418-433-1181-1211z\"/></defs><use xlink:href=\"#DejaVuSans-2212\"/><use x=\"83.789062\" xlink:href=\"#DejaVuSans-30\"/><use x=\"147.412109\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"179.199219\" xlink:href=\"#DejaVuSans-32\"/></g><use x=\"38.482813\" y=\"162.715554\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#79e565cabd1\"/><g transform=\"translate(15.58 166.51) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-30\"/></g><use x=\"38.482813\" y=\"129.007252\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#79e565cabd1\"/><g transform=\"translate(15.58 132.81) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-32\"/></g><use x=\"38.482813\" y=\"95.29895\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#79e565cabd1\"/><g transform=\"translate(15.58 99.098) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-34\"/></g><use x=\"38.482813\" y=\"61.590648\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#79e565cabd1\"/><g transform=\"translate(15.58 65.39) scale(.1 -.1)\" fill=\"#343a3f\"><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-36\"/></g><use x=\"38.482813\" y=\"27.882346\" fill=\"#343a3f\" stroke=\"#343a3f\" stroke-width=\".8\" xlink:href=\"#79e565cabd1\"/><g transform=\"translate(15.58 31.682) scale(.1 -.1)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-38\" transform=\"scale(.015625)\" d=\"m2034 2216q-450 0-708-241-257-241-257-662 0-422 257-663 258-241 708-241t709 242q260 243 260 662 0 421-258 662-257 241-711 241zm-631 268q-406 100-633 378-226 279-226 679 0 559 398 884 399 325 1092 325 697 0 1094-325t397-884q0-400-227-679-226-278-629-378 456-106 710-416 255-309 255-755 0-679-414-1042-414-362-1186-362-771 0-1186 362-414 363-414 1042 0 446 256 755 257 310 713 416zm-231 997q0-362 226-565 227-203 636-203 407 0 636 203 230 203 230 565 0 363-230 566-229 203-636 203-409 0-636-203-226-203-226-566z\"/></defs><use xlink:href=\"#DejaVuSans-30\"/><use x=\"63.623047\" xlink:href=\"#DejaVuSans-2e\"/><use x=\"95.410156\" xlink:href=\"#DejaVuSans-38\"/></g><g fill=\"none\" stroke=\"#000000\"><path d=\"m73.813 94.049v-9.4822\" clip-path=\"url(#9e1b1e44df5)\"/><path d=\"m121.56 162.71v-10.529\" clip-path=\"url(#9e1b1e44df5)\"/><path d=\"m169.3 91.375v-9.4008\" clip-path=\"url(#9e1b1e44df5)\"/><path d=\"m217.04 170.62v-10.533\" clip-path=\"url(#9e1b1e44df5)\"/><path d=\"m264.79 276.33v-8.0015\" clip-path=\"url(#9e1b1e44df5)\"/><path d=\"m312.53 161.72v-10.527\" clip-path=\"url(#9e1b1e44df5)\"/><path d=\"m360.27 41.497v-7.0824\" clip-path=\"url(#9e1b1e44df5)\"/></g><defs><path id=\"d73088c3201\" d=\"m2 0h-4\" stroke=\"#000000\"/></defs><g clip-path=\"url(#9e1b1e44df5)\" stroke=\"#000000\"><use x=\"73.812866\" y=\"94.04893\" xlink:href=\"#d73088c3201\"/><use x=\"121.556181\" y=\"162.712981\" xlink:href=\"#d73088c3201\"/><use x=\"169.299497\" y=\"91.374761\" xlink:href=\"#d73088c3201\"/><use x=\"217.042813\" y=\"170.615294\" xlink:href=\"#d73088c3201\"/><use x=\"264.786128\" y=\"276.334125\" xlink:href=\"#d73088c3201\"/><use x=\"312.529444\" y=\"161.724378\" xlink:href=\"#d73088c3201\"/><use x=\"360.272759\" y=\"41.496544\" xlink:href=\"#d73088c3201\"/></g><g clip-path=\"url(#9e1b1e44df5)\" stroke=\"#000000\"><use x=\"73.812866\" y=\"84.566721\" xlink:href=\"#d73088c3201\"/><use x=\"121.556181\" y=\"152.184282\" xlink:href=\"#d73088c3201\"/><use x=\"169.299497\" y=\"81.973968\" xlink:href=\"#d73088c3201\"/><use x=\"217.042813\" y=\"160.082735\" xlink:href=\"#d73088c3201\"/><use x=\"264.786128\" y=\"268.332618\" xlink:href=\"#d73088c3201\"/><use x=\"312.529444\" y=\"151.197789\" xlink:href=\"#d73088c3201\"/><use x=\"360.272759\" y=\"34.414125\" xlink:href=\"#d73088c3201\"/></g><path d=\"m38.483 288.43v-266.11\" fill=\"none\" stroke=\"#343a3f\" stroke-linecap=\"square\" stroke-width=\".8\"/><path d=\"m38.483 288.43h357.12\" fill=\"none\" stroke=\"#343a3f\" stroke-linecap=\"square\" stroke-width=\".8\"/><g transform=\"translate(92.563 16.318) scale(.12 -.12)\" fill=\"#343a3f\"><defs><path id=\"DejaVuSans-45\" transform=\"scale(.015625)\" d=\"m628 4666h2950v-532h-2319v-1381h2222v-531h-2222v-1691h2375v-531h-3006v4666z\"/><path id=\"DejaVuSans-78\" transform=\"scale(.015625)\" d=\"m3513 3500-1266-1703 1331-1797h-678l-1019 1375-1018-1375h-679l1360 1831-1244 1669h678l928-1247 928 1247h679z\"/><path id=\"DejaVuSans-70\" transform=\"scale(.015625)\" d=\"m1159 525v-1856h-578v4831h578v-531q182 312 458 463 277 152 661 152 638 0 1036-506 399-506 399-1331t-399-1332q-398-506-1036-506-384 0-661 152-276 152-458 464zm1957 1222q0 634-261 995t-717 361q-457 0-718-361t-261-995 261-995 718-361q456 0 717 361t261 995z\"/><path id=\"DejaVuSans-65\" transform=\"scale(.015625)\" d=\"m3597 1894v-281h-2644q38-594 358-905t892-311q331 0 642 81t618 244v-544q-310-131-635-200t-659-69q-838 0-1327 487-489 488-489 1320 0 859 464 1363 464 505 1252 505 706 0 1117-455 411-454 411-1235zm-575 169q-6 471-264 752-258 282-683 282-481 0-770-272t-333-766l2050 4z\"/><path id=\"DejaVuSans-63\" transform=\"scale(.015625)\" d=\"m3122 3366v-538q-244 135-489 202t-495 67q-560 0-870-355-309-354-309-995t309-996q310-354 870-354 250 0 495 67t489 202v-532q-241-112-499-168-257-57-548-57-791 0-1257 497-465 497-465 1341 0 856 470 1346 471 491 1290 491 265 0 518-55 253-54 491-163z\"/><path id=\"DejaVuSans-74\" transform=\"scale(.015625)\" d=\"m1172 4494v-994h1184v-447h-1184v-1900q0-428 117-550t477-122h590v-481h-590q-666 0-919 248-253 249-253 905v1900h-422v447h422v994h578z\"/><path id=\"DejaVuSans-61\" transform=\"scale(.015625)\" d=\"m2194 1759q-697 0-966-159t-269-544q0-306 202-486 202-179 548-179 479 0 768 339t289 901v128h-572zm1147 238v-1997h-575v531q-197-318-491-470t-719-152q-537 0-855 302-317 302-317 808 0 590 395 890 396 300 1180 300h807v57q0 397-261 614t-733 217q-300 0-585-72-284-72-546-216v532q315 122 612 182 297 61 578 61 760 0 1135-394 375-393 375-1193z\"/><path id=\"DejaVuSans-69\" transform=\"scale(.015625)\" d=\"m603 3500h575v-3500h-575v3500zm0 1363h575v-729h-575v729z\"/><path id=\"DejaVuSans-6f\" transform=\"scale(.015625)\" d=\"m1959 3097q-462 0-731-361t-269-989 267-989q268-361 733-361 460 0 728 362 269 363 269 988 0 622-269 986-268 364-728 364zm0 487q750 0 1178-488 429-487 429-1349 0-859-429-1349-428-489-1178-489-753 0-1180 489-426 490-426 1349 0 862 426 1349 427 488 1180 488z\"/><path id=\"DejaVuSans-6e\" transform=\"scale(.015625)\" d=\"m3513 2113v-2113h-575v2094q0 497-194 743-194 247-581 247-466 0-735-297-269-296-269-809v-1978h-578v3500h578v-544q207 316 486 472 280 156 646 156 603 0 912-373 310-373 310-1098z\"/><path id=\"DejaVuSans-76\" transform=\"scale(.015625)\" d=\"m191 3500h609l1094-2937 1094 2937h609l-1313-3500h-781l-1312 3500z\"/><path id=\"DejaVuSans-6c\" transform=\"scale(.015625)\" d=\"m603 4863h575v-4863h-575v4863z\"/><path id=\"DejaVuSans-75\" transform=\"scale(.015625)\" d=\"m544 1381v2119h575v-2097q0-497 193-746 194-248 582-248 465 0 735 297 271 297 271 810v1984h575v-3500h-575v538q-209-319-486-474-276-155-642-155-603 0-916 375-312 375-312 1097zm1447 2203z\"/><path id=\"DejaVuSans-73\" transform=\"scale(.015625)\" d=\"m2834 3397v-544q-243 125-506 187-262 63-544 63-428 0-642-131t-214-394q0-200 153-314t616-217l197-44q612-131 870-370t258-667q0-488-386-773-386-284-1061-284-281 0-586 55t-642 164v594q319-166 628-249 309-82 613-82 406 0 624 139 219 139 219 392 0 234-158 359-157 125-692 241l-200 47q-534 112-772 345-237 233-237 639 0 494 350 762 350 269 994 269 318 0 599-47 282-46 519-140z\"/><path id=\"DejaVuSans-28\" transform=\"scale(.015625)\" d=\"m1984 4856q-418-718-622-1422-203-703-203-1425 0-721 205-1429t620-1424h-500q-468 735-701 1444t-233 1409q0 697 231 1403 232 707 703 1444h500z\"/><path id=\"DejaVuSans-77\" transform=\"scale(.015625)\" d=\"m269 3500h575l719-2731 715 2731h678l719-2731 716 2731h575l-916-3500h-678l-753 2869-756-2869h-679l-915 3500z\"/><path id=\"DejaVuSans-68\" transform=\"scale(.015625)\" d=\"m3513 2113v-2113h-575v2094q0 497-194 743-194 247-581 247-466 0-735-297-269-296-269-809v-1978h-578v4863h578v-1907q207 316 486 472 280 156 646 156 603 0 912-373 310-373 310-1098z\"/><path id=\"DejaVuSans-64\" transform=\"scale(.015625)\" d=\"m2906 2969v1894h575v-4863h-575v525q-181-312-458-464-276-152-664-152-634 0-1033 506-398 507-398 1332t398 1331q399 506 1033 506 388 0 664-152 277-151 458-463zm-1959-1222q0-634 261-995t717-361 718 361q263 361 263 995t-263 995q-262 361-718 361t-717-361-261-995z\"/><path id=\"DejaVuSans-72\" transform=\"scale(.015625)\" d=\"m2631 2963q-97 56-211 82-114 27-251 27-488 0-749-317t-261-911v-1844h-578v3500h578v-544q182 319 472 473 291 155 707 155 59 0 131-8 72-7 159-23l3-590z\"/><path id=\"DejaVuSans-29\" transform=\"scale(.015625)\" d=\"m513 4856h500q468-737 701-1444 233-706 233-1403 0-700-233-1409t-701-1444h-500q415 716 620 1424t205 1429q0 722-205 1425-205 704-620 1422z\"/></defs><use xlink:href=\"#DejaVuSans-45\"/><use x=\"63.183594\" xlink:href=\"#DejaVuSans-78\"/><use x=\"122.363281\" xlink:href=\"#DejaVuSans-70\"/><use x=\"185.839844\" xlink:href=\"#DejaVuSans-65\"/><use x=\"247.363281\" xlink:href=\"#DejaVuSans-63\"/><use x=\"302.34375\" xlink:href=\"#DejaVuSans-74\"/><use x=\"341.552734\" xlink:href=\"#DejaVuSans-61\"/><use x=\"402.832031\" xlink:href=\"#DejaVuSans-74\"/><use x=\"442.041016\" xlink:href=\"#DejaVuSans-69\"/><use x=\"469.824219\" xlink:href=\"#DejaVuSans-6f\"/><use x=\"531.005859\" xlink:href=\"#DejaVuSans-6e\"/><use x=\"594.384766\" xlink:href=\"#DejaVuSans-20\"/><use x=\"626.171875\" xlink:href=\"#DejaVuSans-76\"/><use x=\"685.351562\" xlink:href=\"#DejaVuSans-61\"/><use x=\"746.630859\" xlink:href=\"#DejaVuSans-6c\"/><use x=\"774.414062\" xlink:href=\"#DejaVuSans-75\"/><use x=\"837.792969\" xlink:href=\"#DejaVuSans-65\"/><use x=\"899.316406\" xlink:href=\"#DejaVuSans-73\"/><use x=\"951.416016\" xlink:href=\"#DejaVuSans-20\"/><use x=\"983.203125\" xlink:href=\"#DejaVuSans-28\"/><use x=\"1022.216797\" xlink:href=\"#DejaVuSans-77\"/><use x=\"1104.003906\" xlink:href=\"#DejaVuSans-69\"/><use x=\"1131.787109\" xlink:href=\"#DejaVuSans-74\"/><use x=\"1170.996094\" xlink:href=\"#DejaVuSans-68\"/><use x=\"1234.375\" xlink:href=\"#DejaVuSans-20\"/><use x=\"1266.162109\" xlink:href=\"#DejaVuSans-73\"/><use x=\"1318.261719\" xlink:href=\"#DejaVuSans-74\"/><use x=\"1357.470703\" xlink:href=\"#DejaVuSans-61\"/><use x=\"1418.75\" xlink:href=\"#DejaVuSans-6e\"/><use x=\"1482.128906\" xlink:href=\"#DejaVuSans-64\"/><use x=\"1545.605469\" xlink:href=\"#DejaVuSans-61\"/><use x=\"1606.884766\" xlink:href=\"#DejaVuSans-72\"/><use x=\"1646.248047\" xlink:href=\"#DejaVuSans-64\"/><use x=\"1709.724609\" xlink:href=\"#DejaVuSans-20\"/><use x=\"1741.511719\" xlink:href=\"#DejaVuSans-65\"/><use x=\"1803.035156\" xlink:href=\"#DejaVuSans-72\"/><use x=\"1842.398438\" xlink:href=\"#DejaVuSans-72\"/><use x=\"1881.261719\" xlink:href=\"#DejaVuSans-6f\"/><use x=\"1942.443359\" xlink:href=\"#DejaVuSans-72\"/><use x=\"1983.556641\" xlink:href=\"#DejaVuSans-73\"/><use x=\"2035.65625\" xlink:href=\"#DejaVuSans-29\"/></g><defs><clipPath id=\"9e1b1e44df5\"><rect x=\"38.483\" y=\"22.318\" width=\"357.12\" height=\"266.11\"/></clipPath></defs></svg>"
],
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from math import sqrt\n",
"\n",
"standard_error = [\n",
" sqrt(exp_data[\"variance\"]) / sqrt(exp_data[\"shots\"])\n",
" for exp_data in result.metadata\n",
"]\n",
"\n",
"_, ax = plt.subplots()\n",
"ax.bar(observables_labels, result.values, yerr=standard_error, capsize=2)\n",
"ax.set_title(\"Expectation values (with standard errors)\")"
]
}
],
"metadata": {
"description": "Plot quantum circuit execution results using Qiskit",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3"
},
"title": "Visualize results"
},
"nbformat": 4,
"nbformat_minor": 4
}