matplotlib

plot_date function set xticks for hourly data

感情迁移 提交于 2021-01-29 07:08:42
问题 I currently have a function that creates a time series graph from time/date data that is in MM-DD-YYYY HH-MM format. I am unsure as to how to change the x axis ticks such that it displays hours as well as the date as it currently only shows dates. The set_major_locator line I included only returns ticks that have the year even though I have specified the hour_locator and the data is hourly. def graph(region): fig = plt.figure(num=None, figsize=(60, 20), dpi=100, facecolor='w', edgecolor='k')

Adjust figure size with respect to the axes size?

梦想的初衷 提交于 2021-01-29 07:05:33
问题 Let's say I create a simple plot with matplotlib import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) plot stuff etc .. . After I finished the plotting routines I want to adjust the size of my figure (but keeping all aspect ratios the same), such that the total height of ax is set to a constant value i.e. 3 inches. Is there a nice and short way to archieve this ? EDIT: I know how to change the figure size, but here i want to adjust it according to the size of the axes.

How to have a fast crosshair mouse cursor for subplots in matplotlib?

丶灬走出姿态 提交于 2021-01-29 06:45:18
问题 In this video of backtrader 's matplotlib implementation https://youtu.be/m6b4Ti4P2HA?t=2008 I can see that a default and very fast and CPU saving crosshair mouse cursor seems to exist in matplotlib . I would like to have the same kind of mouse cursor for a simple multi subplot plot in matplotlib like this: import numpy as np import matplotlib matplotlib.use('QT5Agg') matplotlib.rcParams['figure.figsize'] = (20.0, 22.0) import matplotlib.pyplot as plt fig = plt.figure() ax1 = plt.subplot(2, 1

Adding two smaller subplots to the side of my main plot in matplotlib subplots

帅比萌擦擦* 提交于 2021-01-29 06:44:35
问题 Currently my chart is showing only the main big chart on the left. However, I now want to add the two smaller plots to the right-hand side of my main plot; with each individual set of data. I am struggling with subplots to figure out how to do this. My photo below shows my desired output. filenamesK = glob("C:/Users/Ke*.csv") filenamesZ = glob("C:/Users/Ze*.csv") K_Z_Averages = {'K':[], 'Z':[]} # We will create a function for plotting, instead of nesting lots of if statements within a long

matplotlib annotation overlapping y_tick labels on plot

前提是你 提交于 2021-01-29 06:41:50
问题 I have tried a number of different things to fix my chart, from zorder on the plots to plt.rcParams. I feel that this is such a simple problem but I just dont know where I have gone wrong. As you can see the bottom annotation in cyan blue is unreadable and mashed with the y label. Ideally, the annotation sits over the y label to a point where text inside annotation is readable. If possible just for the annotation to sit on top and still overlay the y label..something like this Any help on

Animate scatter plot with colorbar using matplotlib

☆樱花仙子☆ 提交于 2021-01-29 06:32:37
问题 I have spent a serious amount of time trying to animate scatter plot where the colour of the marker is defined by a number. Below is my attempt, which sort of works but not really as planned: After each animation step, the old points should be removed. Instead, the new points are simply added to the points already on plot. The colorbar should also be updated at each step according to the values (just like time text is). However, whatever I seem to do, produces a blank chart. Is this really

How to get a sigmodal CDF curve use scipy.stats.norm.cdf and matplotlib?

孤者浪人 提交于 2021-01-29 06:32:28
问题 I am trying to plot the S-shape cumulative distribution function (cdf) curve of a normal distribution. However, I ended up with a uniform distribution. What am I doing wrong? Test Script import numpy as np from numpy.random import default_rng from scipy.stats import norm import matplotlib.pyplot as plt siz = 1000 rg = default_rng( 12345 ) a = rg.random(size=siz) rg = default_rng( 12345 ) b = norm.rvs(size=siz, random_state=rg) c = norm.cdf(b) print( 'a = ', a) print( 'b = ', b) print( 'c = ',

Animate scatter plot with colorbar using matplotlib

て烟熏妆下的殇ゞ 提交于 2021-01-29 06:20:38
问题 I have spent a serious amount of time trying to animate scatter plot where the colour of the marker is defined by a number. Below is my attempt, which sort of works but not really as planned: After each animation step, the old points should be removed. Instead, the new points are simply added to the points already on plot. The colorbar should also be updated at each step according to the values (just like time text is). However, whatever I seem to do, produces a blank chart. Is this really

How to align or label spider plot variable name?

霸气de小男生 提交于 2021-01-29 06:08:50
问题 I have the following spider plot: I would like to align the variable names (i.e., LABEL_A, LABEL_B, LABEL_C, LABEL_D, VISIT_NAME) such that it is outside the plot (not touching the plot). How do I do that? What I tried so far? plt.xticks(angles[:-1], df1, color='black', size=12, ha = 'center') What should I add to justify the label names /the label names should not tough the graph? Thanks in advance! 回答1: Adjust the horizontal alignment after you plotted the graph depending on the angle

Animating Monte Carlo Method Pi color dots diferently

Deadly 提交于 2021-01-29 06:00:49
问题 I want to have an animation of my plot of my results of the mc method calculating pi; but having the inner circle dots colored differently than the others. How can I do that? This is my code so far: import matplotlib.pyplot as plt import numpy as np from matplotlib.animation import FuncAnimation def punkt_im_quadrat(a,N): #a is length of square, N number of dots """generates random point in [0,a)x[0,a)""" x = a * np.random.random_sample((N,2)) return x #[x,y] def kreis(radius): return np.sqrt