Gnuplot: Bar chart from a function

青春壹個敷衍的年華 提交于 2019-12-11 01:31:47

问题


In difference to nearly 99.9% of all Gnuplot bar chart examples I don't have a data file but a function I want to visualize as a bar chart.

Let us take for example take the simple function f(x) = x

I want a bar char that creates one bar for every value of x between 0 and 20 (step size 1).

Therefore I used the following code, but it does not create 20 bars - it creates a lot more (about 100?).

set xtic 1
set xrange [0:20]
set boxwidth 1
set style fill solid
f(x)=x
plot f(x) with boxes

How to make this bar chart work correctly?


回答1:


You want the set samples command. Try:

set xtic 1
set xrange [0:20]
set boxwidth 1
set style fill solid
f(x)=x
set samples 21
plot f(x) with boxes


来源:https://stackoverflow.com/questions/14174846/gnuplot-bar-chart-from-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!