How to get ˚ in openCV - python-3.x

I want to write ˚ (degree character) in my image. I'm using Python and OpenCV.
The character, however, is shown as ??. This is my code:
import numpy as np
import cv2
import matplotlib.pyplot as plt
read=np.ones((500,500))
temp=100
read=cv2.putText(read,'{:>8.2f} ℃'.format(temp),(20,100), font, 2,(255,255,255),4,cv2.LINE_AA)
plt.imshow(read)
This is the output:

Thanks you, eldesgraciado,
PIL works well
import numpy as np
import cv2
import matplotlib.pyplot as plt
from PIL import Image, ImageFont, ImageDraw
font_path = 'C:\Windows\Fonts\Arial.ttf'
font_size = 48
font = ImageFont.truetype(font_path, font_size)
read=np.ones((500,500))
temp=100
img=Image.fromarray(read)
draw=ImageDraw.Draw(img)
draw.text((0, 50),'{:>9.2f} ˚C'.format(temp), font=font, fill=255)
read=np.array(img)
plt.imshow(read)

Related

How to set the background color in python in phobe2?

How to set the background colour of a figure in phobe2?
import phoebe
from phoebe import u # units
import numpy as np
import matplotlib.pyplot as plt
b = phoebe.default_binary()
b.add_dataset('mesh', times=[0.05], columns=['visibilities'])
b.run_compute(eclipse_method='native')
afig, mplfig = b.plot(component='primary', fc='visibilities', show=True, fcmap='binary_r', draw_sidebars=True)
#afig.set_facecolor('yellow')
Is afig the equivalent of ax in matplotlib, or not?
http://phoebe-project.org/docs/2.3/api/phoebe.parameters.ParameterSet.plot

Cannot configure matplotlib rcparams for plot color

I am not able to change default color from blue to red using plt.rc() or mpl.rcparams
According to Matplotlib's official documentation
Here is the code I tried:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
data = np.random.randn(50)
mpl.rcParams['lines.color'] = 'r'
plt.plot(data)
Output:
If you are using a relatively new matplotlib version (i.e. 1.5+) you should use axes.prop_cycleas described here.
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
data = np.random.randn(50)
import cycler
plt.rcParams['axes.prop_cycle'] = cycler.cycler(color='r')
plt.plot(data)

AttributeError: module 'matplotlib' has no attribute 'scatter'

I'm trying to make cluster of latitude and longitude.
the code gave an error in plt.scatter(data['Lng'],data['Lat']) line
the error is:
AttributeError: module 'matplotlib' has no attribute 'scatter'
code:
import numpy as np
import pandas as pd
import matplotlib as plt
import seaborn as sns
sns.set()
from sklearn.cluster import KMeans
data = pd.read_csv("pk.csv")
data.head()
lat_long = data.drop(['country', 'iso2','admin', 'capital','population',
'population_proper'] , axis = 1)
lat_long.head()
plt.scatter(data['Lng'],data['Lat']) # error here
It should be:
import matplotlib.pyplot as plt
Or it can be:
from matplotlib import pyplot as plt
Also you can read PEP 328 for more information and clearity.

How to scale a data using Python 3

I am trying to scale my data using Python 3
But I keep getting this error: I am out of ideas as to what could be the issue? Please can you assist me guys? I would deeply appreciate your help!
import pandas as pd
import numpy as np
from numpy.random import randn
from pandas import Series, DataFrame
from pandas.plotting import scatter_matrix
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib import rcParams
from pylab import rcParams
import seaborn as sb
import scipy
from scipy import stats
from scipy.stats import pearsonr
from scipy.stats import spearmanr
from scipy.stats import chi2_contingency
import sklearn
from sklearn import preprocessing
from sklearn.preprocessing import scale
mtcars = pd.read_csv('mtcars.csv')
mtcars.columns = ['Car
names','mpg','cyl','disp','hp','drat','wt','qsec','vs','am','gear','carb']
mpg = mtcars['mpg']
#Scale your data
mpg_matrix = mpg.reshape(-1,1)
scaled = preprocessing.MinMaxScaler()
scaled_mpg = scaled.fit_transform(mpg_matrix)
plt.plot(scaled_mpg)
plt.show()
mpg_matrix = mpg.numpy.reshape(-1,1)
tr__
File "C:\Anaconda\lib\site-packages\pandas\core\generic.py", line 5067, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'numpy'
pandas.core.series.Series doesn't have reshape.
Perhaps:
mpg_matrix = mpg.values.reshape(-1,1)
i.e. get the underlying numpy array and reshape that.

Plotting multiple boxplots group by two columns

import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
import pandas as pd
filepath='E:/PROJECT ON DATA SCIENCE/boxplot/fee.csv';
X=pd.read_csv(filepath_or_buffer=filepath,index_col=0)
X.boxplot(by='stype', column='fee')
X.boxplot(by='pincode', column='fee')
If you want to boxplot X grouping by both stype and pincode you can use
X.boxplot(column='fee', by=['stype', 'pincode'])
Complete code would be
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
import pandas as pd
filepath='E:/PROJECT ON DATA SCIENCE/boxplot/fee.csv';
X=pd.read_csv(filepath_or_buffer=filepath,index_col=0)
X.boxplot(column='fee', by=['stype', 'pincode'])

Resources