matplotlib

python matplotlib scatter plot colors error

只谈情不闲聊 提交于 2021-02-05 11:50:29
问题 I am trying to create a scatter plot with x and y grid where every point gets a color by a preassigned value: {x: 1, y: 2, value: n} I have a list of x and y and another list for the values, tried using this: # make range of x(0 - 359) and y(-90 - 90) x, y = np.meshgrid(range(0, 360), range(-90, 90)) colors = [a very long list (64800 values, one for each point)] print(colors) plt.scatter(x, y, c=colors) plt.colorbar() plt.show() Errors: Traceback (most recent call last): File "C:\python3.6.6

python matplotlib scatter plot colors error

孤者浪人 提交于 2021-02-05 11:50:04
问题 I am trying to create a scatter plot with x and y grid where every point gets a color by a preassigned value: {x: 1, y: 2, value: n} I have a list of x and y and another list for the values, tried using this: # make range of x(0 - 359) and y(-90 - 90) x, y = np.meshgrid(range(0, 360), range(-90, 90)) colors = [a very long list (64800 values, one for each point)] print(colors) plt.scatter(x, y, c=colors) plt.colorbar() plt.show() Errors: Traceback (most recent call last): File "C:\python3.6.6

Title of figure between the subplots

妖精的绣舞 提交于 2021-02-05 11:48:53
问题 When I make a figure with two subplots in the following way: import matplotlib.pyplot as plt fig=plt.figure(1) (ax1,ax2) = fig.subplots(2,1, gridspec_kw={'height_ratios':[1,15]}) the title appears between the subplots: plt.title('Title') plt.show() How can I have the title on the top of the figure instead? 回答1: What you are looking for is suptitle which places a centered title at the top of the figure. Using plt.title (applies to the current axis which is ax2 in your case) import matplotlib

Title of figure between the subplots

[亡魂溺海] 提交于 2021-02-05 11:47:37
问题 When I make a figure with two subplots in the following way: import matplotlib.pyplot as plt fig=plt.figure(1) (ax1,ax2) = fig.subplots(2,1, gridspec_kw={'height_ratios':[1,15]}) the title appears between the subplots: plt.title('Title') plt.show() How can I have the title on the top of the figure instead? 回答1: What you are looking for is suptitle which places a centered title at the top of the figure. Using plt.title (applies to the current axis which is ax2 in your case) import matplotlib

Adjust y-axis in Seaborn multiplot

喜夏-厌秋 提交于 2021-02-05 11:24:52
问题 I'm plotting a CSV file from my simulation results. The plot has three graphs in the same figure fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(24, 6)) . However, for comparison purposes I want the y-axis in all graphs starting at zero and the ending at a specific value. I tried the solution mentioned here from the Seaborn author. I don't get any errors, but the solution also does not work for me. Here's my script: import pandas as pd import matplotlib.pyplot as plt import seaborn as sns

plotting wrong on x axis

こ雲淡風輕ζ 提交于 2021-02-05 10:59:48
问题 thank you for reading my question I have to plot my data like that. When I plot my data I am having an output like this. Code for reading the data from the file and plotting is below #!/usr/bin/env python3.8 import matplotlib.pyplot as plt import numpy as np with open('data.txt','r') as file2: y= [line.rstrip('\n') for line in file2] notf2=y[2:] z=[a.rstrip(' ') for a in notf2] x_data=[] y_data=[] for j in range(0, len(z)): x_data += [z[j][:3]] y_data += [z[j][5:]] x__data=[] y__data=[] for k

Error after using PyInstaller for script with Matplotlib

两盒软妹~` 提交于 2021-02-05 10:50:49
问题 In my code I am using: import matplotlib.pyplot as plt import matplotlib.image as mpimg When I build the .py script, everything works fine. But after using the pyinstaller.exe to get the executable file, I get following error: Traceback (most recent call last): File "C:\Program Files\Python38\Scripts\excel_to_python.py", line 10, in <module> File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "

mplcursors: show and highlight coordinates of nearby local extreme

梦想与她 提交于 2021-02-05 09:41:43
问题 I have code that shows the label for each point in a matplotlib scatterplot using mplcursors, similar to this example. I want to know how to, form a list of values, make a certain point stand out, as in if I have a graph of points y=-x^2 . When I go near the peak, it shouldn't show 0.001, but 0 instead, without the trouble needing to find the exact mouse placement of the top. I can't solve for each point in the graph, as I don't have a specific function. 回答1: Supposing the points in the

mplcursors: show and highlight coordinates of nearby local extreme

纵然是瞬间 提交于 2021-02-05 09:41:00
问题 I have code that shows the label for each point in a matplotlib scatterplot using mplcursors, similar to this example. I want to know how to, form a list of values, make a certain point stand out, as in if I have a graph of points y=-x^2 . When I go near the peak, it shouldn't show 0.001, but 0 instead, without the trouble needing to find the exact mouse placement of the top. I can't solve for each point in the graph, as I don't have a specific function. 回答1: Supposing the points in the

X and Y label being cut in matplotlib plots

我与影子孤独终老i 提交于 2021-02-05 09:40:44
问题 I have this code: import pandas as pd from pandas import datetime from pandas import DataFrame as df import matplotlib from pandas_datareader import data as web import matplotlib.pyplot as plt import datetime start = datetime.date(2016,1,1) end = datetime.date.today() stock = 'fb' fig = plt.figure(dpi=1400) data = web.DataReader(stock, 'yahoo', start, end) fig, ax = plt.subplots(dpi=720) data['vol_pct'] = data['Volume'].pct_change() data.plot(y='vol_pct', ax = plt.gca(), title = 'this is the