In matplotlib, I want to make a line using matplotlib.pyplot which is alternating black and yellow dashes, and then I want to include that line on the legend. How do I do that? I could do something like: but then the line on the legend would appear as a solid black line, rather than as black-and-yellow dashes. I did look
Tag: matplotlib
Format y axis as percent
I have an existing plot that was created with pandas like this: The y axis is format as float and I want to change the y axis to percentages. All of the solutions I found use ax.xyz syntax and I can only place code below the line above that creates the plot (I cannot add ax=ax to the line above.)
Python hide ticks but show tick labels
I can remove the ticks with but this removes the labels as well. Any way I can plot the tick labels but not the ticks and the spine Answer You can set the tick length to 0 using tick_params (http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.tick_params):
Increase resolution with word-cloud and remove empty border
I am using word cloud with some txt files. How do I change this example if I wanted to 1) increase resolution and 2) remove empty border. Answer You can’t increase the resolution of the image in plt.show() since that is determined by your screen, but you can increase the size. This allows it to scale, zoom, etc. without blurring.
Plotting in a non-blocking way with Matplotlib
I am having problems trying to make matplotlib plot a function without blocking execution. I have tried using show(block=False) as some people suggest, but all I get is a frozen window. If I simply call show(), the result is plotted properly but execution is blocked until the window is closed. From other threads I’ve read, I suspect that whether show(block=False)
Matplotlib’s fill_between doesnt work with plot_date, any alternatives?
I want to create a plot just like this: The code: but with dates in the x axis, like this (without bands): the code: the problem is that fill_between fails when x values are date_time objects. Does anyone know of a workaround? DF is a pandas DataFrame. Answer It would help if you show how df is defined. What does
Matplotlib error: libfreetype.6.dylib
I’m trying to run the following python script (I’m using Vim): When I do, I get the following: I tried reinstalling brew, reinstalling freetype, matplotlib, and numpy in brew, and I uninstalled MacPorts with no change in the error. Suggestions? EDIT: After uninstalling MacPorts and then doing another reinstall of brew, I now get this error instead. Fatal Python error:
is it possible to append figures to Matplotlib’s PdfPages?
I want to save 2 figures created at different parts of a script into a PDF using PdfPages, is it possible to append them to the pdf? Example: Answer Sorry, that’s a lame question. We just shouldn’t use the with statement.
Python: Matplotlib avoid plotting gaps
I am currently generating the plot below: with this code: where intra.to_pydatetime() is a: <bound method DatetimeIndex.to_pydatetime of <class ‘pandas.tseries.index.DatetimeIndex’> [2011-01-03 09:35:00, …, 2011-01-07 16:00:00] Length: 390, Freq: None, Timezone: None> So the dates go from 2011-01-03 09:35:00, increments by 5 minutes until 16:00:00, and then jumps to the next day, 2011-01-04 09:35:00 until 2011-01-04 16:00:00, and so on. How
How do I bin and categorize numbers in Python?
I’m not sure if binning is the correct term, but I want to implement the following for a project I am working on: I have an array or maybe a dict describing boundaries and/or regions, for example: The areas are indexed from 0 to 100 (for example). I want to classify each area into a color (that is less than