matplotlib

Matplotlib: Add color legend to scatter plot

丶灬走出姿态 提交于 2021-01-29 14:21:35
问题 Have table as: import matplotlib.pyplot as plt import pandas as pd import numpy as np list_1=[['AU',152,474.0], ['CA',440,482.0], ['DE',250,564.0,], ['ES',707,549.0,], ['FR',1435,551.0,], ['GB',731,555.0,], ['IT',979,600.0,], ['NDF',45041,357.0,], ['NL',247,542.0,], ['PT',83,462.0,], ['US',20095,513.0,], ['other',3655,526.0,]] labels=['country_destination','num_users','avg_hours_spend'] df=pd.DataFrame(list_1,columns=labels) df=df.set_index('country_destination') df country_destination num

Exit recursion for matplotlib events

安稳与你 提交于 2021-01-29 14:05:37
问题 I have a little matplotlib figure with a button_press_event . Inside the listener I use plt.pause to make a short animation for every click. This works fine and as expected. However if I click again before the animation is over, I enter a recursion and the remaining animations are played at the end. If you click fast enough you can even reach the RecursionError . What do I need to change, so a new click discards all remaining steps in the on_click method? import numpy as np import matplotlib

ValueError: could not convert string to float: when using matplotlib, arduino and pyqt5

筅森魡賤 提交于 2021-01-29 14:02:21
问题 While using an arduino code (also connecting pin 13 to A0 in an arduino uno) to have changing values int PinOutput = 13; int PinInput = A0; int inph; int inpl; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(PinInput, INPUT); pinMode(PinOutput, OUTPUT); } void loop() { // put your main code here, to run repeatedly: inpl = analogRead(PinInput)/4; Serial.println(inpl); analogWrite(PinOutput,255); delay(1000); inph = analogRead(PinInput)/4; Serial.println

Plotting multiple subplot animations

梦想与她 提交于 2021-01-29 13:43:55
问题 I am currently trying to plot four simultaneous animations in a 2x2 matplotlib matrix. My code is as follows: x1 = np.random.normal(0, 1, 1000) x2 = np.random.gamma(0, 1.5, 1000) x3 = np.random.exponential(2, 1000) x4 = np.random.uniform(0,20, 1000) import matplotlib.animation as animation n = 1000 def update(curr): # check if animation is at the last frame, and if so, stop the animation a if curr == n: a.event_source.stop() plt.cla() fig , ax = plt.subplots(2,2,figsize=(5,3),sharex=False

Bokeh update map tooltip using select or slider

不打扰是莪最后的温柔 提交于 2021-01-29 13:01:07
问题 I am trying to update a worldmap tooltip using a slicer or dropdown select. I got following question which sorted the most of the stuff for a Bokeh Slider custom JS callback import pandas as pd import random from datetime import timedelta df = pd.DataFrame({'base' : ["2017-01-01" for t in range(10000)], 'Date' : [random.randint(0, 1035) for t in range(10000)], 'Sales' : [random.random() for t in range(10000)]}) df['base'] = pd.to_datetime(df['base']) df["Date2"] = df.apply(lambda x: x["base"]

Create a combination of “relative” and “grouped” chart in Python

你。 提交于 2021-01-29 12:51:10
问题 I need to create a combination of "relative" and "grouped" chart in plotly. I figured out how to create stacked and grouped by using this code: from plotly import graph_objects as go import plotly pyplt = plotly.offline.plot data = { "Sports_19": [15, 23, 32, 10, 23, 22, 32, 24], "Casual_19": [4, 12, 11, 14, 15, 12, 22, 14], "Yoga_19": [4, 8, 18, 6, 12, 11, 10, 4], "Sports_20": [11, 18, 18, 0, 20, 12, 12, 11], "Casual_20": [20, 10, 9, 6, 10, 11, 17, 22], "Yoga_20": [11, 18, 18, 0, 20, 12, 12,

Matplotlib histogram not counting correctly the number of values in each bin

独自空忆成欢 提交于 2021-01-29 12:43:46
问题 I am trying to make a very simple histogram with matplotlib.pyplot.hist, and it seems not to be counting properly the number of values in each bin. Here is my code: import numpy as np import matplotlib.pyplot as plt plt.hist([.2,.3,.5,.6],bins=np.arange(0,1.1,.1)) I am dividing the interval [0,1] in bins of width .1, so I should get four bars of height 1. But the output figure consists of only two bars of height 2: it is counting the .3 value as part of the [.2,.3) bin and, similarly, it is

interpolate curve between three values

戏子无情 提交于 2021-01-29 12:42:24
问题 I have the following script that plots a graph: x = np.array([0,1,2]) y = np.array([5, 4.31, 4.01]) plt.plot(x, y) plt.show() The problem is, that the line goes straight from point to point, but I want to smooth the line between the points. If I use scipy.interpolate.spline to smooth my data I got following result: order = np.array([0,1,2]) y = np.array([5, 4.31, 4.01]) xnew = np.linspace(order.min(), order.max(), 300) smooth = spline(order, y, xnew) plt.plot(xnew, smooth) plt.show() But I

How to plot two lists of tuples with Matplotlib

天大地大妈咪最大 提交于 2021-01-29 12:41:19
问题 I have two lists where each element is a tuple that should be interpreted as x = [(x1_begin, x1_end), (x2_begin, x2_end), ... , (xn_begin, xn_end)] y = [(y1_begin, y1_end), (y2_begin, y2_end), ... , (yn_begin, yn_end)] In one figure, I would like to plot all these points and draw lines only between (yi_begin, yi_end) vs (xi_begin, xi_end) for all i. The following code manages to plot all the points. But I'm not sure how to draw the lines properly between the points. Any help is much

Seaborn heatmap is generating additional ticks on colorbar when using log scale

你离开我真会死。 提交于 2021-01-29 11:26:39
问题 I am trying to make a heatmap with logarithmic colorbar. But it keeps generating its own ticks and ticklabels along with the ones I input. I originally posted this to reformat the tick labels from scientific notation to plain but then ran into this problem. import numpy as np import seaborn as sns from matplotlib.colors import LogNorm import matplotlib.ticker as tkr matrix = np.random.rand(10, 10)/0.4 vmax=2 vmin=0.5 cbar_ticks = [0.5, 0.75, 1, 1.33, 2] formatter = tkr.ScalarFormatter