ggplot2 plot area margins?

You can adjust the plot margins with plot.margin in theme() and then move your axis labels and title with the vjust argument of element_text(). For example : library(ggplot2) library(grid) qplot(rnorm(100)) + ggtitle(“Title”) + theme(axis.title.x=element_text(vjust=-2)) + theme(axis.title.y=element_text(angle=90, vjust=-0.5)) + theme(plot.title=element_text(size=15, vjust=3)) + theme(plot.margin = unit(c(1,1,1,1), “cm”)) will give you something like this : If you want … Read more

Moving x-axis to the top of a plot in matplotlib

Use ax.xaxis.tick_top() to place the tick marks at the top of the image. The command ax.set_xlabel(‘X LABEL’) ax.xaxis.set_label_position(‘top’) affects the label, not the tick marks. import matplotlib.pyplot as plt import numpy as np column_labels = list(‘ABCD’) row_labels = list(‘WXYZ’) data = np.random.rand(4, 4) fig, ax = plt.subplots() heatmap = ax.pcolor(data, cmap=plt.cm.Blues) # put the major … Read more

How to plot a histogram using Matplotlib in Python with a list of data?

If you want a histogram, you don’t need to attach any ‘names’ to x-values because: on x-axis you will have data bins on y-axis counts (by default) or frequencies (density=True) import matplotlib.pyplot as plt import numpy as np %matplotlib inline np.random.seed(42) x = np.random.normal(size=1000) plt.hist(x, density=True, bins=30) # density=False would make counts plt.ylabel(‘Probability’) plt.xlabel(‘Data’); Note, … Read more

How can I run Tensorboard on a remote server?

Here is what I do to avoid the issues of making the remote server accept your local external IP: when I ssh into the machine, I use the option -L to transfer the port 6006 of the remote server into the port 16006 of my machine (for instance): ssh -L 16006:127.0.0.1:6006 olivier@my_server_ip What it does … Read more

Plot correlation matrix using pandas

You can use pyplot.matshow() from matplotlib: import matplotlib.pyplot as plt plt.matshow(dataframe.corr()) plt.show() Edit: In the comments was a request for how to change the axis tick labels. Here’s a deluxe version that is drawn on a bigger figure size, has axis labels to match the dataframe, and a colorbar legend to interpret the color scale. … Read more

How do I convert a numpy array to (and display) an image?

The following should work: from matplotlib import pyplot as plt plt.imshow(data, interpolation=’nearest’) plt.show() If you are using Jupyter notebook/lab, use this inline command before importing matplotlib: %matplotlib inline A more featureful way is to install ipyml pip install ipympl and use %matplotlib widget see an example.

How to make IPython notebook matplotlib plot inline

I used %matplotlib inline in the first cell of the notebook and it works. I think you should try: %matplotlib inline import matplotlib import numpy as np import matplotlib.pyplot as plt You can also always start all your IPython kernels in inline mode by default by setting the following config options in your config files: … Read more

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