-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove autoscale view call from plot_state_hinton #4811
Conversation
This commit removes the use of matplotlib's autoscale_view() [1] from the plot state hinton visualization. This function is truncating the plot if there are axis that are empty. This is not really necessary for the hinton function anyway since we have fixed limits on the plots as we add the ticks based on the shape of the input matrix. However it was being used to handle boxes on edges of the graph (ie when the top row or right most edge had a box) that wouldn't be properly centered. This commit worksaround that by padding both sides of the tick list to ensure the data is always centered. Fixes Qiskit#4249 [1] https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.autoscale_view.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing something. Here is the output on the branch mtreinish:fix-hinton
:
from qiskit import QuantumCircuit, BasicAer, execute, visualization
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0,1)
qc.z(1)
backend = BasicAer.get_backend('statevector_simulator')
job = execute(qc, backend=backend)
sv = job.result().get_statevector(qc)
visualization.plot_state_hinton(sv)
Ugh, yeah it looks like everything is off by one now, in that case. I only tested the bug case and it worked fine for that, but clearly this needs more adjustment |
With @chriseclectic fix on top of my branch this works fine with the example before: so this should be good to go now. |
Summary
This commit removes the use of matplotlib's autoscale_view() [1] from
the plot state hinton visualization. This function is truncating the
plot if there are axis that are empty. This is not really necessary for
the hinton function anyway since we have fixed limits on the plots as we
add the ticks based on the shape of the input matrix. However it was
being used to handle boxes on edges of the graph (ie when the top row or
right most edge had a box) that wouldn't be properly centered. This
commit worksaround that by padding both sides of the tick list to ensure
the data is always centered.
Details and comments
[1] https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.autoscale_view.html
Co-authored-by: Christopher J. Wood cjwood@us.ibm.com
Fixes #4249