xkcd style graphs in MATLAB

I see two ways to solve this: The first way is to add some jitter to the x/y coordinates of the plot features. This has the advantage that you can easily modify a plot, but you have to draw the axes yourself if you want to have them xkcdyfied (see @Rody Oldenhuis’ solution). The second … Read more

Minimizing NExpectation for a custom distribution in Mathematica

As far as I see, the problem is (as you already wrote), that MeanResidualLife takes a long time to compute, even for a single evaluation. Now, the FindMinimum or similar functions try to find a minimum to the function. Finding a minimum requires either to set the first derivative of the function zero and solve … Read more

How to plot two histograms together in R?

Here is an even simpler solution using base graphics and alpha-blending (which does not work on all graphics devices): set.seed(42) p1 <- hist(rnorm(500,4)) # centered at 4 p2 <- hist(rnorm(500,6)) # centered at 6 plot( p1, col=rgb(0,0,1,1/4), xlim=c(0,10)) # first histogram plot( p2, col=rgb(1,0,0,1/4), xlim=c(0,10), add=T) # second The key is that the colours are … Read more

Is there a way to detach matplotlib plots so that the computation can continue?

Use matplotlib‘s calls that won’t block: Using draw(): from matplotlib.pyplot import plot, draw, show plot([1,2,3]) draw() print(‘continue computation’) # at the end call show to ensure window won’t close. show() Using interactive mode: from matplotlib.pyplot import plot, ion, show ion() # enables interactive mode plot([1,2,3]) # result shows immediatelly (implicit draw()) print(‘continue computation’) # at … Read more

Plot two histograms on single chart with matplotlib

Here you have a working example: import random import numpy from matplotlib import pyplot x = [random.gauss(3,1) for _ in range(400)] y = [random.gauss(4,2) for _ in range(400)] bins = numpy.linspace(-10, 10, 100) pyplot.hist(x, bins, alpha=0.5, label=”x”) pyplot.hist(y, bins, alpha=0.5, label=”y”) pyplot.legend(loc=”upper right”) pyplot.show()

Matplotlib different size subplots

Another way is to use the subplots function and pass the width ratio with gridspec_kw matplotlib Tutorial: Customizing Figure Layouts Using GridSpec and Other Functions matplotlib.gridspec.GridSpec has available gridspect_kw options import numpy as np import matplotlib.pyplot as plt # generate some data x = np.arange(0, 10, 0.2) y = np.sin(x) # plot it f, (a0, … Read more

Why do many examples use `fig, ax = plt.subplots()` in Matplotlib/pyplot/python

plt.subplots() is a function that returns a tuple containing a figure and axes object(s). Thus when using fig, ax = plt.subplots() you unpack this tuple into the variables fig and ax. Having fig is useful if you want to change figure-level attributes or save the figure as an image file later (e.g. with fig.savefig(‘yourfilename.png’)). You … Read more

How to set limits for axes in ggplot2 R plots?

Basically you have two options scale_x_continuous(limits = c(-5000, 5000)) or coord_cartesian(xlim = c(-5000, 5000)) Where the first removes all data points outside the given range and the second only adjusts the visible area. In most cases you would not see the difference, but if you fit anything to the data it would probably change the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)