I am plotting with matplotlib and trying to get a nice layout like plotly. Especially I would like to have a bar chart/box plot with filling and contour in the same colour. Not as default black/grey contour and coloured contour but like plotly. Any suggestions without stylesheet?
The following is solved:
Because by searching for the solution I found style sheets, but I get the following error message trying to load specific stylesheets in python matplotlib following the official manual:
>>> import matplotlib.pyplot as plt
>>> plt.style.use('ggplot')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'style'
same problem with:
>>> print plt.style.available
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'style'
Information about the system:
>>> matplotlib.__version__
'1.3.1'
So it seems that something is wrong with my installation, but what can I do? Any suggestions?
As shown in the release notes, the style package was added in matplotlib 1.4. You will need to upgrade if you want to use that.
Related
I'm learning how to use qiskit and I'm using the jupyter notebook, but everytime I try to visualize the circuit with the attribute draw I get this error:
import qiskit
from qiskit import *
from qiskit import IBMQ
qr = QuantumRegister(2)
cr = ClassicalRegister(2)
circuit = QuantumCircuit(qr, cr)
%matplotlib inline
circuit.draw(output='mpl')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-8-bd220039ee1c> in <module>
----> 1 circuit.draw(output='mpl')
AttributeError: module 'qiskit.circuit' has no attribute 'draw'
I also try applying a Hadamard gate and I get:
circuit.h(qr(0))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-59-c8b4318b743b> in <module>
----> 1 circuit.h(qr(0))
AttributeError: module 'qiskit.circuit' has no attribute 'h'
It seems that there is a name conflict. It is taking the circuit in from qiskit import circuit instead of circuit = ....
You just probably need to restat your notebook kernel.
Try another name for your circuit variable, right now python thinks you want the qiskit.circuit module to draw something. QuantumCircuit objects are the ones that have a draw method. You can see these two objects here if you call both, note I put one qubit and classical bit in the QuantumCircuit just per example as well you do not need the dots here it is just to make it more clear, just running circuit and QuantumCircuit(1,1) respectively would yield the same result.
You would get desired results if you tried a different variable name:
When I try using the variable name circuit it works for me, but try to use descriptive variable names that also could never be confused with modules or classes from the packages you import.
Also all your import statements can be combined into 1:
from qiskit import *
The star lets you import everything from qiskit including IBMQ. It can help you save a line or two.
I am looking for a straightforward way of applying automatic white balance to an image.
I found some official documentation about a balanceWhite() method: cv::xphoto::WhiteBalancer Class Reference
However, I have an obscure error when I try to call the function as shown in the example.
image = cv2.xphoto_WhiteBalancer.balanceWhite(image)
Raises:
Traceback (most recent call last):
File "C:\Users\Delgan\main.py", line 80, in load
image = cv2.xphoto_WhiteBalancer.balanceWhite(image)
TypeError: descriptor 'balanceWhite' requires a 'cv2.xphoto_WhiteBalancer' object but received a 'numpy.ndarray'
If then I try to use a cv2.xphoto_WhiteBalancer object as required:
balancer = cv2.xphoto_WhiteBalancer()
cv2.xphoto_WhiteBalancer.balanceWhite(balancer, image)
It raises:
Traceback (most recent call last):
File "C:\Users\Delgan\main.py", line 81, in load
cv2.xphoto_WhiteBalancer.balanceWhite(balancer, image)
TypeError: Incorrect type of self (must be 'xphoto_WhiteBalancer' or its derivative)
Did anyone succeeded to use this feature with Python 3.6 and OpenCV 3.4?
I also tried with derived classes GrayworldWB, LearningBasedWB and SimpleWB but errors are the same.
The answer can be found in the xphoto documentation.
The appropriate methods to create the WB algorithms are createSimpleWB(), createLearningBasedWB() and createGrayworldWB().
Example:
wb = cv2.xphoto.createGrayworldWB()
wb.setSaturationThreshold(0.99)
image = wb.balanceWhite(image)
Here is a sample file in the official OpenCV repository: modules/xphoto/samples/color_balance_benchmark.py
I'm new to Python (and am using Spyder) and am trying to create some histograms of when the top movies from IMDB were created. I have imported the matplotlib, numpy and pandas, as well as the .txt file, but when I run the following lines of code:
plt.hist(data.year, bins=np.arange(1950, 2013), color='#cccccc')
I receive an error message:
Traceback (most recent call last):
File "stdin", line 1, in <module>
AttributeError: 'module' object has no attribute 'hist'
What am I doing wrong?
Your question provide very poor information and insight in your code. More data..
Meanwhile check if you actually import your modules correctly, should have:
import matplotlib.pyplot as plt
in order to use hist function
The generate method of nltk.text.Text seems to have been removed in NLTK 3.0.
For example:
>>> bible = nltk.corpus.gutenberg.words(u'bible-kjv.txt')
>>> bibleText = nltk.Text(bible)
>>> bibleText.generate()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Text' object has no attribute 'generate'
It may just be that I'm remembering wrongly how to do this, but everything I can find online seems to support the above method. Any ideas what I'm doing wrong?
A note in the first online chapter of the NLTK book says that:
The generate() method is not available in NLTK 3.0 but will be
reinstated in a subsequent version.
I want to draw a 2d histogram with python. I found following example on the matplotlib wiki
from pylab import *
x = randn(1000)
y = randn(1000)+5
#normal distribution center at x=0 and y=5
hist2d(x,y,bins=40)
show()
But i get the error
> Traceback (most recent call last): File "./hist2d_demo.py", line 9,
> in <module>
> hist2d(x,y,bins=40) NameError: name 'hist2d' is not defined
Anyone has an idea how i can fix that?
I just copypasted your code sample in my python 2.7.6 and it works perfectly.
I also have numpy 1.8.0, scipy 0.9.0 and matplotlib 1.3.0 installed.
Your version of matplotlib may be too old, check it this way :
import matplotlib
print matplotlib.__version__