Gnuplot: how to mimic sketch graphs - gnuplot

I want to plot a figure like this one:
but with only sketched data curves. The x and y axes should not be sketched.
Is this possible using Gnuplot?

I think you may find this link useful, since it's exactly what you are asking for :)
http://rfonseca.github.io/xkcd-gnuplot/
Essentially, it applies a function to jiggle the line and make it pseudo-hand-drawn:
jiggle(x) = x*(1+(2*rand(0)-0.5)*0.015)
plot jiggle(sin(x))
And this is the result:
You may also want to increase samples with set samples 1000 to have better results avoiding spikes in jiggled lines.
(As a curiosity, that page is inspired by a StackExchange answer, that contains a very advanced (and amazing, IMHO) approach to this problem, unfortunately only for Mathematica users.)

Related

Overlapping/crowded labels on y-axis python [duplicate]

This question already has answers here:
How to change spacing between ticks
(4 answers)
Closed 5 months ago.
I'am kind of in a rush to finish this for tomorrows presentation towards the project owner. We are a small group of economic students in germany trying to figure out machine learning with python. We set up a Random Forest Classifier and are desperate to show the estimators important features in a neat plot. By applying google search we came up with the following solution that kind of does the trick, but leaves us unsatisfied due to the overlapping of the labels on the y-axis. The code we used looks like this:
feature_importances = clf.best_estimator_.feature_importances_
feature_importances = 100 * (feature_importances / feature_importances.max())
sorted_idx = np.argsort(feature_importances)
pos = np.arange(sorted_idx.shape[0])
plt.barh(pos, feature_importances[sorted_idx], align='center', height=0.8)
plt.yticks(pos, df_year_four.columns[sorted_idx])
plt.show()
Due to privacy let me say this: The feature names on the y-axis are overlapping (there are about 30 of them). I was looking into the documentation of matplotlib in order to get an understanding of how to do this by myself, unfortunately I couldn't find anything helpful. Seems like training and testing models is easier than understanding matplotlib and creating plots :D
Thank you so much for helping out and taking the time, I appreciate it.
I see your solution, and I want to just add this link here to explain why: How to change spacing between ticks in matplotlib?
The spacing between ticklabels is exclusively determined by the space between ticks on the axes. Therefore the only way to obtain more space between given ticklabels is to make the axes larger.
The question I linked shows that by making the graph large enough, your axis labels would naturally be spaced better.
You are using np.argsort that will return a numpy array with many indices. And you are using that array as labels for your Y-Axis thus there is overlapping of labels.
My suggestion will be to use an index for sorted_idx like,
plt.yticks(pos, df_year_four.columns[sorted_idx[0]])
This will plot only for 1 label.
Got it guys!
'Geistesblitz' as we say in germany! (spiritual lightening)
See the variable feature_importances in the third top row? Add feature_importnaces[:-15]
to view only the top half of the features and loosen up the y-axis. Yes!!! This does well because there are way less important features.

OpenGL in iOS: lines drawn are very not smooth

I am working on a graphic application in which the user draws lines.
The lines are not smooth. I see the problem especially when drawing the lines slowly.
What would be the correct way to smoothen the lines?
I read the following great article: http://www.merowing.info/2012/04/drawing-smooth-lines-with-cocos2d-ios-inspired-by-paper/
It fixed some of the problem, but not all of it. Still, when drawing lines slowly, they look jagged:
The problem is actually that you have too many sample points.
This is why the problem is exacerbated when the user inputs points slowly, rather than quickly. One possible solution is to use some sort of best-fitting line equation (e.g. Least Squares) to reduce the number of points and simplify it to an approximation.
There are more sophisticated approaches to smoothing user input, but in this simple case all you really need to do is reduce the sample size.

Using images for points in gnuplot

I have a frivolous question. Is there any way to use an image in lieu of points in gnuplot? For example, if I was plotting data about pasta consumption or something, I would have pictures of pasta (instead of usual gnuplot points).
Another option is to find a dingbats type of font with a suitable glyph. Then you can use "plot with labels" using that glyph as the label string. See for example the 5th plot in the demo
http://gnuplot.sourceforge.net/demo/stringvar.html
I haven't played around with this feature at all myself, however, there is:
http://gnuplot.sourceforge.net/demo/barchart_art.html
Which shows the use of png files on a bar chart (Note, that this feature was added in Gnuplot 4.5 -- I think). With a little creativity, it seems like you could use that feature to do what you're asking -- although it would require a whole bunch of plot commands so it might be useful to write a script to generate the gnuplot script (or use iteration depending on your dataset) -- Obviously your image files would have to be in a format that your version of gnuplot understands as well ...
A possible strategy may be the plot with rgbimage option in gnuplot.
See the second example over here: http://www.gnuplot.info/demo_4.2/image.html
If you relate the center option with your data points, this may be possible.

How can I draw an implicit function f(x,y,z)=0 with gnuplot?

I want to draw the following implicit function with gnuplot
x**2+y**2+(z-1)**3-2
I know that maple or matlab can to this very simple but I want to use gnuplot.
Up to know I have no idea so I can't provide a starting point.
sorry
Here the result plotted with maple
According to the Gnuplot FAQ, this is not directly possible. There is a workaround for 2D-functions, but I don't see how this method can be applied to 3D graphs. I'd recommend solving the equation in Octave or some similar program and outputting the solutions to a file, which you can then feed into GnuPlot.

Gnuplot fine grained ranges(grid)

I have this graph created with gnuplot
However the red line at the bottom seems like very straight due to the y-axis range although it is not (it should look like the blue one). How can make the range of the y-axis very fine grained (lots of ticks) so very small values of the red graph can be visible ? Hope I was clear thanks.
I can think of two possible solutions to your question.
Use a logarithmic scale with set logscale y. This would change the look of your plot quite a bit but you would still have all the data related to a single scale and it would most probably introduce a "higher resolution" to your red line.
Introduce a second y-axis like in this example.
As far as I know, it is not possible to increase the resolution only on a specific part of an axis. I think, this would lead to more confusion than it would do any good.

Resources