matplotlib

How to use NetworkX's rescale_layout?

和自甴很熟 提交于 2021-02-11 13:11:44
问题 I am having a hard time understanding how to use NetworkX's rescale_layout. The documentation says: pos (numpy array) – positions to be scaled. Each row is a position which is not the standard "position dictionary" that the rest of NetworkX uses for plotting. I have tried to use NetworkX's to_numpy_array on the "pos dict" to no success, and the output of to_numpy_array is a Graph adjacency matrix which doesn't mesh with the requirement of rescale_layout 's Each position is one row of the

I'm reading images on the disk, how to plot like the first 50 images?

穿精又带淫゛_ 提交于 2021-02-11 13:11:08
问题 I am reading images on the disk, how to make a for and where to put it to plot the first 50 images on the screen, I want to make sure, that I'm reading the right images, it's for deep learning. def load_clef_database(): img_data_list = [] dataset_dir = "/Users/PlantCLEF2015" root = os.path.join(dataset_dir, 'train') filenames = [] # files class_species = [] class_species_unique = [] class_species_unique_id = [] class_familys = [] class_geni = [] class_ids = [] class_contents = [] metadata = [

How to get the associated axis of a bar chart in python Matplotlib

故事扮演 提交于 2021-02-11 12:55:23
问题 I am learning Matplotlib through practice and have created 2 subplots in a figure and drew two bar charts. I tried adding the height using text function using 2 nested for loops. Here's the code: import numpy as np import matplotlib.pyplot as plt rns = np.random.randn(50) fig,(ax1,ax2) = plt.subplots(2,1,figsize=(10,6)) barg = ax1.bar(range(50),rns) barg2 = ax2.bar(range(50),rns**2) fig.subplots_adjust(hspace=0.6) for bargr in [barg,barg2]: for bar in bargr: reading = round(bar.get_height(),2

How to resample a .wav sound file which is being read using the wavfile.read?

﹥>﹥吖頭↗ 提交于 2021-02-11 12:54:25
问题 I want to change the following two lines of my code: clip, sample_rate = librosa.load(file_name) clip = librosa.resample(clip, sample_rate, 2000) I want to load the .wav file using wavfile.read() instead of using librosa.load() and then resample it using some technique other than the libroa.resample() . Any idea how to do it? 回答1: So here is the answer folks! The below solution worked for me. from scipy.io import wavfile import scipy.signal as sps from io import BytesIO new_rate = 2000 # Read

How can I fix the issue based on showing image in each horizontal bar in subplot area in Python?

人走茶凉 提交于 2021-02-11 12:50:14
问题 I have a problem about showing image in each bar of horizontal bar plot in subplot (2 row , 2 column) in Python. My aim is to devise a subplot based on 2 row and 2 column and then draw horizontal bar related with dataframe with each image putting in each bar. Image format is " png ". I wrote a code snippet shown below but it didn't work. Only one bar with related with appeared in each horizontal bar. f,a = plt.subplots(2,2,figsize=(18,14)) f.subplots_adjust(wspace = 0.5, hspace=0.4) colors_1

Plotting string values acquired from CSV stream on Python

我怕爱的太早我们不能终老 提交于 2021-02-11 12:49:43
问题 I don't have strong Python & programming background, and currently I am stuck on plotting data/values which I acquired from csv stream. Currently, this is what I have to just print the values streamed from .csv (real-time data from sensor), which I acquired from here: def follow(thefile): thefile.seek(0,2) #file handling on the data stream while True: line = thefile.readline() if not line: time.sleep(0.1) continue yield line logfile = open("C:/Users/ra/Desktop/mon23.csv","r") loglines =

How to horizontally center a bar plot annotation?

落花浮王杯 提交于 2021-02-11 12:44:10
问题 I am creating a bar chart like this: gender = ['M', 'F'] numbers = [males,females] bars = plt.bar(gender, numbers, width=0.1, bottom=None, align='center', data=None) for i in range(len(numbers)): plt.annotate(str(numbers[i]), xy=(gender[i],numbers[i])) plt.show() I want to use plt.annotate to write the exact value on the top of the bar. However, the value is printed towards the right side. Is it possible to move it to the center? 回答1: In order to specify the horizontal alignment of the

Integrating Plotly inside WxPython

邮差的信 提交于 2021-02-11 12:43:53
问题 Plotly says it is a web library. Matplotlib does support Wxpython but comparatively, it is too low level. Is there any way to integrate Plotly inside a Wxpython GUI or are there any alternative for it? 回答1: You might be able to use Plotly's ability to export plots to images to get the plots into wxPython: https://plot.ly/python/offline/#static-image-export If you need the live plotting though, then you will need to use Webview: https://wxpython.org/Phoenix/docs/html/wx.html2.WebView.html I

Integrating Plotly inside WxPython

允我心安 提交于 2021-02-11 12:43:39
问题 Plotly says it is a web library. Matplotlib does support Wxpython but comparatively, it is too low level. Is there any way to integrate Plotly inside a Wxpython GUI or are there any alternative for it? 回答1: You might be able to use Plotly's ability to export plots to images to get the plots into wxPython: https://plot.ly/python/offline/#static-image-export If you need the live plotting though, then you will need to use Webview: https://wxpython.org/Phoenix/docs/html/wx.html2.WebView.html I

plot doesn't update on button click but does when window resized

穿精又带淫゛_ 提交于 2021-02-11 12:35:08
问题 What's going on: Program in python3/qt5/matplotlib. I am plotting three subplots and few plots in each. I wanted to update plots if user changes any data. That proved rather complicated hence the button 'Replot'. It calls a function that clears canvas and ... reloads the entire widget. It doesn't work as expected: when I press the button nothing happens, but when window gets resized after button clicked it does update the plot. What would be a correct way to do it without having to put all