python SyntaxError: invalid syntax %matplotlib inline

if you are not using Jupyter IPython notebook, just comment out (or delete) the line, everything will work fine and a separate plot window will be opened if you are running your python script from the console. However, if you are using Jupyter IPython notebook, the very first python code cell in your notebook should … Read more

How to add title to seaborn boxplot

Seems pretty Googleable but haven’t been able to find something online that works. I’ve tried both sns.boxplot(‘Day’, ‘Count’, data= gg).title(‘lalala’) and sns.boxplot(‘Day’, ‘Count’, data= gg).suptitle(‘lalala’). None worked. I think it might be because I’m also working with matplotlib.

Remove xticks in a matplotlib plot?

The plt.tick_params method is very useful for stuff like this. This code turns off major and minor ticks and removes the labels from the x-axis. Note that there is also ax.tick_params for matplotlib.axes.Axes objects.

How can I set the aspect ratio in matplotlib?

Third times the charm. My guess is that this is a bug and Zhenya’s answer suggests it’s fixed in the latest version. I have version 0.99.1.1 and I’ve created the following solution: Below are my unsuccessful, yet hopefully informative attempts. Second Answer: My ‘original answer’ below is overkill, as it does something similar to axes.set_aspect(). I think you … Read more

Changing the “tick frequency” on x or y axis in matplotlib

You could explicitly set where you want to tick marks with plt.xticks: For example, (np.arange was used rather than Python’s range function just in case min(x) and max(x) are floats instead of ints.) The plt.plot (or ax.plot) function will automatically set default x and y limits. If you wish to keep those limits, and just change the stepsize of the tick marks, then you could use ax.get_xlim() to discover what limits Matplotlib … Read more

Plot a horizontal line using matplotlib

You are correct, I think the [0,len(xs)] is throwing you off. You’ll want to reuse the original x-axis variable xs and plot that with another numpy array of the same length that has your variable in it. Hopefully that fixes the problem

How to draw vertical lines on a given plot in matplotlib

The standard way to add vertical lines that will cover your entire plot window without you having to specify their actual height is plt.axvline OR You can use many of the keywords available for other plot commands (e.g. color, linestyle, linewidth …). You can pass in keyword arguments ymin and ymax if you like in axes corrdinates (e.g. ymin=0.25, ymax=0.75 will cover the middle half of the … Read more