All the matplotlib examples with hist() generate a data set, provide the data set to the hist function with some bins (possibly non-uniformly spaced) and the function automatically calculates and then plots the histogram. I already have histogram data and I simply want to plot it, how can I do that?! For example, I have the bins (half open ranges
Tag: matplotlib
Placing text values on axis instead of numeric values
I’ve created a simple word frequency calculator in python 3.2. Now I want to create a plot to visualize the results. The x-axis would contain frequency results and I want to add the most frequent words to the y-axis. How can I add text instead of numbers to a pylab axis? Thanks in advance! Answer I am going to assume,
matplotlib 2d line line,=plot comma meaning
I’m walking through basic tutorials for matplotlib, and the example code that I’m working on is: Does anyone know what the comma after line (line,=plt.plot(x,y,’-‘)) means? I thought it was a typo but obviously the whole code doesn’t work if I omit the comma. Answer plt.plot returns a list of the Line2D objects plotted, even if you plot only one
Using arctan / arctan2 to plot a from 0 to 2π
I am trying to replicate a plot in Orbital Mechanics by Curtis, but I just can’t quite get it. However, I have made head way by switching to np.arctan2 from np.arctan. Maybe I am implementing arctan2 incorrectly? In the image below, there are discontinuities popping up. The function is supposed to be smooth and connect at 0 and 2 pi
matplotlib: Group boxplots
Is there a way to group boxplots in matplotlib? Assume we have three groups “A”, “B”, and “C” and for each we want to create a boxplot for both “apples” and “oranges”. If a grouping is not possible directly, we can create all six combinations and place them linearly side by side. What would be to simplest way to visualize
no module named pylab on windows
I faced this issue yesterday. I saw the following questions: No module named pylab python error: no module named pylab Both of the above questions gave instructions for Linux and not for Windows machines. The Problem I have heard about the pylab package for plotting in python. I opened the shell and tried this and… I then installed matplotlib and
How to return a matplotlib.figure.Figure object from Pandas plot function
I have a dt: And use pandas function plot to create a barplot object But I want a <matplotlib.figure.Figure object> instead to pass to other function, just like the object type below: So how can I transform <matplotlib.axes.AxesSubplot object> to <matplotlib.figure.Figure object> or directly return “Figure object” from Pandas plot ? Answer You can get the figure from the axes
change the colorbar width
I have created this, as you can see the colorbar is very thin, is there anyway of increasing the width of the colorbar without increasing the height Answer You need to get hold of the axes of the colorbar. Assuming you hold a reference to the colorbar in cbar you get to the axes via cbar.ax. You can control the
Matplotlib discrete colorbar
I am trying to make a discrete colorbar for a scatterplot in matplotlib I have my x, y data and for each point an integer tag value which I want to be represented with a unique colour, e.g. typically tag will be an integer ranging from 0-20, but the exact range may change so far I have just used the
Adding a y-axis label to secondary y-axis in matplotlib
I can add a y label to the left y-axis using plt.ylabel, but how can I add it to the secondary y-axis? Answer The best way is to interact with the axes object directly