I am new with Python and I would like to have a histogram of the values that I have in a text file. But I get a Histogram with only the first value of my text file (See figure)
enter image description here
My file text is as follows:
2.52549
2.52821
4.69718
4.81173
4.85834
4.87637
3.03348
3.21677
3.28373
3.11296
3.11947
3.14685
3.19684
3.19533
3.20035
3.36578
3.3899
3.40696
3.47841
3.54231
3.54343
5.20521
5.23496
5.23317
6.1397
6.18261
6.18782
6.1184
6.20701
6.25631
And my code as follows
import matplotlib.pyplot as plt
import numpy as np
import plotly.plotly as py
from pylab import show,hist
gaussian_numbers = np.random.randn(1000)
data_Distanz = np.genfromtxt('data_Distance.txt')
x = data_Distanz[0]
plt.hist(x)
plt.title("Histogram")
plt.xlabel("Distance in m")
plt.ylabel("Amplitude")
plt.savefig('Histogram.png', bbox_inches='tight')
show()
I Would appreciate your help. Thanks in advance!
Related
I would like to change the label of in the colorbar of an healpix mollview plot.
I can change the font size but not the text, any suggestion ?
In the following example, the outputs are -2 and 0.
Thank you !
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
import healpy as hp
# create figure
d = np.arange(12*16**2)
hp.mollview(d, title='Hello', unit=r'T', notext=False, coord=['G','C'], cmap=cm.magma)
f = pplot.gcf().get_children()
HpxAx = f[1]
CbAx = f[2]
CbAx.get_children()[8].get_children()[2].get_children()[3].set_fontsize(40)
CbAx.get_children()[8].get_children()[2].get_children()[3].set_text("-2")
print(CbAx.get_children()[8].get_children()[2].get_children()[3].get_text())
plt.show()
print(CbAx.get_children()[8].get_children()[2].get_children()[3].get_text())
I am trying to read data from a txt file containing 200 values and then trying to plot a histogram based on the data. However, there are too many values on the xticks, and I do not know how to fix this.
My code:
import math
import numpy as np
import matplotlib.pyplot as plt
f=open('LedData.rtf',"r")
lines=f.readlines()
result=[]
for x in lines:
result.append(x.split(',')[1])
f.close()
plt.hist(result)
plt.xticks(rotation = 'vertical')
plt.show
Histogram : Here is an image for reference.
Thanks for any help.
import numpy as np
from matplotlib_venn import venn2, venn2_circles, venn2_unweighted
from matplotlib_venn import venn3, venn3_circles
from matplotlib import pyplot as plt
plt.title(print("Shared",Signature_1, 'and',Signature_2, 'and',Signature_3))
venn3(subsets = (len(NameA), len(NameB), len(shared_A_B), len(NameC), len(shared_A_C),
len(shared_C_B), len(shared_A_B_C)), set_labels = (Signature_1, Signature_2, Signature_3), alpha = 0.5)
plt.show()
This code produces titles for plots in jupyter notebook only. When I run the .py script in Anaconda prompt only the plot is visible. How would I go about getting the titles to appear in the plot window? I realized because these are formatted to take variables [plt.title(print("title",variable,etc.)] that they do not work in command line. Any suggestions would be appreciated
You can use the .format method to include a variable into the print/title.
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0,10)
y = x**2
plt.plot(x,y)
variable ='IamVar'
Signature_1='one'
Signature_2='two'
Signature_3='three'
# \n stands for newline
plt.suptitle("Moving title - {} and {},{} \n set=({},{})".format(Signature_1,Signature_2,Signature_3,len(x),len(y))
,size=8,x=0.3, y=0.6)
plt.show()
I am using pandas to import a csv to my notebook, and I changed any blank data column to a blank space. When I use plt.plot to make a graph of the data it turns out with a bunch of black lines on the x and y axis. Below is my code and graph:
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
apo2data = pd.read_csv('/Users/lilyloyer/Desktop/Apo2excel.csv')
apo2data.isnull()
data = apo2data.fillna(" ")
teff=data['Teff (K)']
grav=data['logg_seis']
plt.plot(teff, grav, 'ro')
How does matplotlib ensure that a dataset can be within plot with specified size.
How do i from a plot stored as numpy, How do i read the color of the pixels illustration a datapoint (0,4) - in the plot.
example:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from PIL import Image
import librosa
import librosa.display
from matplotlib import cm
fig = plt.figure(figsize=(12,4))
min = -1.828067
max = 22.70058
data = np.random.uniform(low=min, high=max, size=(474,40))
librosa.display.specshow(data.T,sr=16000,x_axis='frames',y_axis='mel',hop_length=160,cmap=cm.jet)
plt.show()
raw_input("sadas")
convert = plt.get_cmap(cm.jet)
numpy_output_static = convert(data.T)
plt.imshow(numpy_output_static, aspect = 'auto')
plt.show()
raw_input("asds")
First plot being :
Second plot being:
so the first has been resized to plot size 12,4 where the last basically plots the same data but just using the data shape as size... how do i change that?
Librosa just performs pcolormesh according to the GitHub source code
You need to define another figure with its own size for the second figure.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from PIL import Image
import librosa
import librosa.display
from matplotlib import cm
fig = plt.figure(figsize=(12,4))
min = -1.828067
max = 22.70058
data = np.random.uniform(low=min, high=max, size=(474,40))
librosa.display.specshow(data.T,sr=16000,x_axis='frames',y_axis='mel',hop_length=160,cmap=cm.jet)
plt.show()
raw_input("sadas")
convert = plt.get_cmap(cm.jet)
numpy_output_static = convert(data.T)
fig = plt.figure(figsize=(12,4))
plt.imshow(numpy_output_static, aspect = 'auto')
plt.show()
raw_input("asds")